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
Comparison of various fibonnaci functions. (The recursive function is limited to fib(20) because it breaks on my pc for high values - it's an advantage, but I'm not expecting it to reach high scores)
Revision 2: extended the limit to 25 for the recursive function - because other browsers are apparently better at it and make it appear more performant than the iterative function. (If it's still better, just keep in mind that the recursive function has an easier test case than the rest of them)
number = 0;
function rec(n){
if(n === 0) { return 0; }
if(n === 1) { return 1; }
else { return rec(n-2) + rec(n-1); }
}
function rec_tail(n) {
function tc_rec(x,y,c){
if (c === 0) { return x; }
else { return tc_rec(y, x+y, c-1); }
}
return tc_rec(0,1,n);
}
function rec_tail_loga(n){
function tc_rec(a,b,p,q,c){
if(c === 0){ return b; }
if(c % 2 === 0){ return tc_rec(a, b, q*q+p*p, q*(q+2*p), c/2); }
else { return tc_rec(b*q+a*q+a*p, b*p+a*q, p, q, c-1); }
}
return tc_rec(1,0,0,1,n);
}
function iter(n){
var x=0, y=1, c=0, t;
while(c !== n){
t=x; x=y; y+=t; c++;
}
return x;
}
number = 0;
Ready to run.
Test | Ops/sec | |
---|---|---|
recursive |
| ready |
tail recursive |
| ready |
tail recursive (log) |
| ready |
iterative |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.