window.addEventListener("load",async ()=> { async function nnDecompress(blob) { const ds = new DecompressionStream("gzip"); const decompressedStream = blob.stream().pipeThrough(ds); return await (await new Response(decompressedStream).blob()).text(); } async function nnCompress(blob) { const cs = new CompressionStream("gzip"); const compressedStream = blob.stream().pipeThrough(cs); return await new Response(compressedStream).blob(); } var info = document.createElement("div"); info.innerHTML="both
test A: (new TextEncoder()).encode(str) and
test B: new Blob([str])
will block the UI thread equally

" info.style.color="blue"; document.body.appendChild(info); var textarea = document.createElement("textarea"); textarea.textContent=""; textarea.style.width="90vw"; textarea.style.height="100vh"; document.body.appendChild(textarea); for(var i=0; i<=23; i++) { let bytes = 1 << i; let array = new Uint8Array(bytes); let zerozipped = await nnCompress(new Blob([array])); crypto.getRandomValues(array); let zipped = await nnCompress(new Blob([array])); textarea.textContent+="\n"+i+"\n"+"with "+bytes+" bytes"+"\n"+ "===> "+zipped.size+" compression ("+(((zipped.size/bytes*10000)|0)/100)+"%)\n"+ "===> "+zerozipped.size+" compression ("+(((zerozipped.size/bytes*10000)|0)/100)+"%)\n"+ Array.from(new Uint8Array(await zipped.slice(0,32).arrayBuffer())).map((e)=>{ return ("0"+e.toString(16)).slice(-2);}).join(" ")+"\n"; Array.from(new Uint8Array(await zerozipped.slice(0,32).arrayBuffer())).map((e)=>{ return ("0"+e.toString(16)).slice(-2);}).join(" ")+"\n"; } },false);