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
Testing out how slow recursion actually is.
<script>
var index = 20;
var r5 = Math.sqrt(5);
var phi = (1 + r5) / 2;
function fibonacci_recursive(n) {
if (n < 2) return n;
return fibonacci_recursive(n - 2) + fibonacci_recursive(n - 1);
}
function fibonacci_loop(n) {
if (n < 2) return n;
var previous = 0;
var current = 1;
var next;
for (var i = 1; i < n; i++) {
next = previous + current;
previous = current;
current = next;
}
return current;
}
function fibonacci_direct(n) {
if (n < 2) return n;
return (Math.pow((1 + r5) / 2, n) - Math.pow((1 - r5) / 2, n)) / r5;
}
function fibonacci_direct2(n) {
if (n < 2) return n;
var r5 = Math.sqrt(5);
var phi = (1 + r5) / 2;
return (Math.pow((1 + r5) / 2, n) - Math.pow((1 - r5) / 2, n)) / r5;
}
function fibonacci_round(n) {
if (n < 2) return n;
return Math.round(Math.pow(phi, n) / r5);
}
function fibonacci_round2(n) {
if (n < 2) return n;
var r5 = Math.sqrt(5);
var phi = (1 + r5) / 2;
return Math.round(Math.pow(phi, n) / r5);
}
</script>
Ready to run.
Test | Ops/sec | |
---|---|---|
recursive |
| ready |
loop |
| ready |
direct |
| ready |
round |
| ready |
direct2 |
| ready |
round2 |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.