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 fib = (n) => {
if (n <= 2) {
result = 1;
} else {
result = fib(n-1) + fib(n-2);
}
return result;
};
const memo = [];
const fib2 = (n, memo = []) => {
if (memo[n]) {
return memo[n];
}
let result;
if (n <= 2) {
result = 1;
} else {
result = fib2(n - 1, memo) + fib2(n - 2, memo);
}
memo[n] = result;
return result;
};
const fib3 = (n) => {
const memo = [0, 1, 1]; // Initialize memo with base cases
for (let i = 3; i <= n; i++) {
memo[i] = memo[i - 1] + memo[i - 2];
}
return memo[n];
};
const fib4 = (n) => {
let a = 0, b = 1, c;
if (n < 3) {
if (n < 0) return fib(-n);
if (n === 0) return 0;
return 1;
}
while (--n)
c = a + b, a = b, b = c;
return c;
}
const fib5 = (n) => {
var i;
var resultsArray = [];
for (i = 0; i <= n; i++) {
if (i === 0) {
resultsArray.push(0);
} else if (i === 1) {
resultsArray.push(1);
} else {
resultsArray.push(resultsArray[i - 2] + resultsArray[i - 1]);
}
}
return resultsArray[n];
}
Ready to run.
Test | Ops/sec | |
---|---|---|
Fib (Naive) |
| ready |
Better Fib |
| ready |
Bottom-up Fib |
| ready |
Weird SO Fib |
| ready |
Another Weird SO Fib |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.