Last active
October 18, 2020 23:16
-
-
Save techsin/41a1791296c0650240e77c14d615f97f to your computer and use it in GitHub Desktop.
Testing performance of service workers vs promises
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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