Skip to content

Instantly share code, notes, and snippets.

@techsin
Last active October 18, 2020 23:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save techsin/41a1791296c0650240e77c14d615f97f to your computer and use it in GitHub Desktop.
Save techsin/41a1791296c0650240e77c14d615f97f to your computer and use it in GitHub Desktop.
Testing performance of service workers vs promises
function wrk() {
var blobURL = URL.createObjectURL(new Blob(['(',
function () {
for (let i = 0; i < 5000000000; i++) { } console.log(1000);
}.toString(),
')()'], { type: 'application/javascript' }));
const worker = new Worker(blobURL);
URL.revokeObjectURL(blobURL);
worker.onmessage = (e) => console.log(e.data);
worker.postMessage(null)
}
wrk()
wrk()
wrk()
//all values get logged together
async function prom() {for(let i = 0; i < 5000000000; i++) {} console.log(1000);}
prom()
prom()
prom()
//promises are async but not parrallel, still single threaded..
//logs with delays
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment