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>
/*
* memoize.js
* by @philogb and @addyosmani
* further optimizations by @mathias
* Released under an MIT license.
*/
function memoize2( fn ) {
return function () {
var args = Array.prototype.slice.call(arguments),
hash = "",
i = args.length;
toString = Object.prototype.toString,
callEm = toString.call({}),
currentArg = null;
while(i--){
currentArg = args[i];
hash += (callEm == toString.call(currentArg)) ?
JSON.stringify(currentArg) : currentArg;
fn.memoize || (fn.memoize = {});
}
return (hash in fn.memoize) ? fn.memoize[hash] :
fn.memoize[hash] = fn.apply( this , args );
};
}
//stoyans version
function memoize7(param){
if (!memoize7.cache) {
memoize7.cache = {};
}
if (!memoize7.cache[param]) {
var result = fib(param);
memoize7.cache[param] = result;
}
return memoize7.cache[param];
}
var fib, fiborg, f;
fiborg = fib = f = function (x) {
if(x < 2) return 1; else return fib(x-1) + fib(x-2);
}
</script>
Ready to run.
Test | Ops/sec | |
---|---|---|
Memoize2 |
| ready |
Directly calling |
| ready |
Memoize7 |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.