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
let target = 2000;
let expected = target * (target + 1) / 2;
function* range(n) {
for (let i = 1; i <= n; i++) {
yield i;
}
}
function sumToImperative(n) {
let result = 0;
for (let i = 1; i <= n; i++) {
result += i;
}
return result;
}
function sumToGenerator(n) {
let result = 0;
for (let i of range(n)) {
result += i;
}
return result;
}
function sumToRecursive(n, sum = 0) {
return n === 0 ? sum : sumToRecursive(n - 1, sum + n);
}
function sumToTrampoline(n) {
function go(n, sum = 0) {
return n === 0 ? sum : () => go(n - 1, sum + n);
}
let result = go(n);
while (typeof result === 'function') {
result = result();
}
return result;
}
function assert(cond) {
if (!cond) {
throw new Error('Bad math');
}
}
Ready to run.
Test | Ops/sec | |
---|---|---|
For Loop |
| ready |
Generator |
| ready |
Recursive |
| ready |
Trampoline |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.