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
Test function call overhead for classical functions, member functions and recursive functions.
<script>
var test1 = [], test2 = [], test3 = [], test,
limit = 100000,
MAX_CALL_DEPTH = 100 - 1;
for (var i = 0; i < limit; i++) {
test1.push((i * 33.3333 + 3.14152729) % 256);
test2[i] = NaN;
test3[i] = Infinity;
}
test = test1;
function fun(num) {
return test[num];
}
function fun2(dst, src, idx) {
return dst + src;
}
function fun3(i, depth) {
if (depth === MAX_CALL_DEPTH) {
return test[i];
} else {
return test[i] + fun3(i + 1, depth + 1);
}
}
function fun4(i, cps) {
return function (value) {
cps(test[i] + value);
};
}
var o;
o = {
fun: fun,
fun2: fun2,
fun3: function fun3(i, depth) {
if (depth === MAX_CALL_DEPTH) {
return test[i];
} else {
return test[i] + o.fun3(i + 1, depth + 1);
}
},
fun5: function fun5(v, i, depth, cps) {
if (depth === MAX_CALL_DEPTH) {
cps(v + test[i]);
} else {
o.fun5(v + test[i], i + 1, depth + 1, cps);
}
},
};
</script>
var test2 = 0;
console.log('test2 = ', test2);
Ready to run.
Test | Ops/sec | |
---|---|---|
control |
| ready |
Looped function calls |
| ready |
Looped function calls with caching |
| ready |
Looped function calls using call |
| ready |
looped function calls using member |
| ready |
Looped function without closure use |
| ready |
Recursive function |
| ready |
Recursive function method |
| ready |
Flattened recursion via queue |
| ready |
Looped function without closure access |
| ready |
Function with CPS |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.