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
<script>
function memoize1(func) {
"use strict";
var cache={},
stringifyJson = JSON.stringify,
sliceArray = Array.prototype.slice,
u;
return function() {
var hash = stringifyJson(sliceArray.call(arguments));
var foo=cache[hash];
return foo===u?cache[hash]=func.apply(this, arguments):foo;
};
};
function memoize2(func) {
"use strict";
var cache={},ret,
stringifyJson = JSON.stringify,
sliceArray = Array.prototype.slice,
u;
if(func.length!=1){ret=function() {
var hash = stringifyJson(sliceArray.call(arguments));
var foo=cache[hash];
return foo===u?cache[hash]=func.apply(this, arguments):foo;
}}else{ ret=function(a) {
var u,foo=cache[a];
return foo===u?cache[a]=func(a):foo;
}}
return ret
};
var fib1, fib2, fiborg, numb=10;
fiborg = function f(x) {
if(x < 2) return 1; else return f(x-1) + f(x-2);
}
fib1=memoize1(fiborg);
fib2=memoize2(fiborg);
</script>
numb=(Math.random()*40)|0
Ready to run.
Test | Ops/sec | |
---|---|---|
without argument length detection |
| ready |
with argument length detection |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.