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
const size = 10000000;
function getArrayValueDifferenceReduce(a, b) {
let diff = 0;
if (a.length === b.length) {
return diff;
}
return (
b.reduce((acc, curr) => acc + curr, 0) -
a.reduce((acc, curr) => acc + curr, 0)
);
}
function getArrayValueDifferenceReduceOptim(a, b) {
function sum(a, b) {
return a + b;
}
let diff = 0;
if (a.length === b.length) {
return diff;
}
return (
b.reduce(sum, 0) -
a.reduce(sum, 0)
);
}
function getArrayValueDifferenceLoop(a, b) {
let diff = 0;
if (a.length === b.length) {
return diff;
}
for (let i = 0; i < b.length; i++) {
diff += b[i];
}
for (let i = 0; i < a.length; i++) {
diff -= a[i];
}
return diff;
}
Ready to run.
Test | Ops/sec | |
---|---|---|
reduce |
| ready |
reduce optim |
| ready |
loop |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.