import{ref as n,onMounted as F,createElementBlock as h,openBlock as C,createElementVNode as i,createCommentVNode as N,unref as e,toDisplayString as r,createTextVNode as l}from"/vue.js";import{n as S}from"./nc-main.DEgIQeOo.js";import"./service-worker.DGZzV4eE.js";const T={key:0,style:{color:"red"}},R=["disabled"],U={style:{"font-weight":"bold"}},V=!0,A=1e5,x=256,k="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",H=Object.assign({name:"measure-memory"},{__name:"measure-memory",setup(E){let c=!window.performance?.memory;c&&(c=S.isSafari()?"Safari":S.isFirefox()?"Firefox":"unknown browser");const s=n(!0),y=n([]),B=n([]);let f=n(0),w=n(0),p=n(0),g=n(0),M=n(0),v=n(0),d=n(0);const u=new Intl.NumberFormat("fi-FI",{maximumSignificantDigits:6}).format;async function m(a,t){if(t&&window.performance?.measureUserAgentSpecificMemory){const o=await performance.measureUserAgentSpecificMemory();if(console.debug("🚀 ~ measureUserAgentSpecificMemory:",o),o.bytes)return Math.round((o.bytes/Math.pow(1e3,2)-a)*10)/10}return window.performance?.memory?Math.round((window.performance.memory.usedJSHeapSize/Math.pow(1e3,2)-a)*10)/10:0}async function b(){f.value=await m(0,!0),w.value=await m(0)}F(()=>{s.value=!0,b(),s.value=!1});function D(){let a="";for(let t=0;t<x;t++)a+=k.charAt(Math.floor(Math.random()*k.length));return a}async function _(a){s.value=!0,a&&a.preventDefault();let t=new Date().getMilliseconds();d.value+=A,f.value===0&&b();for(let o=0;o<A;o++)t+=864e5,y.value.push({date:t,text:D()});setTimeout(async()=>{p.value=await m(0,!0),g.value=await m(0);for(let o=0;o<d.value;o+=1)B[o]=y.value[o];setTimeout(async()=>{M.value=await m(p.value,!0),v.value=await m(p.value),s.value=!1},400)},400)}return(a,t)=>(C(),h("div",null,[t[3]||(t[3]=i("h2",null,"Memory Consumption Demo",-1)),e(c)?(C(),h("h3",T,"Results do not show in "+r(e(c))+" because window.performance is not supported.",1)):N("",!0),i("p",null,[t[0]||(t[0]=l(" Click the button to measure memory consumption: ",-1)),i("button",{disabled:e(s),onClick:_},"Remeasure Memory",8,R)]),i("p",null,[t[1]||(t[1]=l(" Test with ",-1)),i("b",null,"pointer array: "+r(V)+", characters "+r(x)),l(", using   "+r(e(u)(e(d)))+" element array ",1)]),i("p",null,"Memory consumption before creating first array:            "+r(e(u)(e(f)))+" / "+r(e(u)(e(w)))+" MB.",1),i("p",null," Additional memory consumption after creating 1. normal array: "+r(e(u)(e(p)))+" / "+r(e(u)(e(g)))+" MB. ",1),i("p",null,[t[2]||(t[2]=l(" Additional memory consumption after creating 2. ",-1)),i("span",U,r("pointer"),1),l(" array: "+r(e(u)(e(M)))+" / "+r(e(u)(e(v)))+" MB. ",1)])]))}});export{H as default};
