jsPerf.app is an online JavaScript performance benchmark test runner & jsperf.com mirror. It is a complete rewrite in homage to the once excellent jsperf.com now with hopefully a more modern & maintainable codebase.
jsperf.com URLs are mirrored at the same path, e.g:
https://jsperf.com/negative-modulo/2
Can be accessed at:
https://jsperf.app/negative-modulo/2
In a research project, I noticed that many simultaneous Workers with small messages start to congest the main thread handling them all. So check the throughput of messages to a single Worker vs. a pool of Workers. More Workers appear to be slower for the same total number of messages.
Interestingly, when only using MessageChannels within a single thread, it is faster to spread the messages across multiple channels ...
let wrkr = 100;
let msgs = 100 * wrkr;
// create workers with inline script blobs
let script = "onmessage = ({data}) => postMessage({ id: data.id })";
let blob = URL.createObjectURL(new Blob([script]));
let workers = Array(wrkr).fill().map(() => new Worker(blob));
// pre-create promises with external resolvers
let resolver = Array(msgs).fill();
let promises = Array(msgs).fill().map((_, i) => new Promise(r => resolver[i] = r));
// register promise resolvers on workers
workers.forEach(p => p.onmessage = ({data}) => resolver[data.id]());
workers.forEach(w => w.terminate());
Ready to run.
Test | Ops/sec | |
---|---|---|
All messages to a single Worker |
| ready |
Spread messages to some Workers |
| ready |
Spread messages to all Workers |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.