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
A comparison of compact memoization routines providing the bare minimum functionality necessary for caching.
<script src="http://underscorejs.org/underscore-min.js"></script>
<script>
window.underscore = window._;
delete window._;
console.info("underscore is: " + window.underscore);
</script>
<script src="https://rawgithub.com/lodash/lodash/2.4.1/dist/lodash.min.js"></script>
<script>
window.lodash = window._;
delete window._;
console.info("lodash is: " + window.lodash);
</script>
<script src="http://rawgit.com/lodash/lodash/master/dist/lodash.min.js"></script>
<script>
window.lodashLatest = window._;
delete window._;
console.info("lodashLatest is: " + window.lodashLatest);
</script>
<script>
var fib = function(x) {
if (x < 2) return 1;
else return fib(x - 1) + fib(x - 2);
}
// compact memoizer
function memoize1(param) {
this.memoize = this.memoize || {};
return (param in this.memoize) ? this.memoize[param] : this.memoize[param] = fib(param);
}
// using an external cache
var memCache = {};
function memoize2(param, cache) {
cache = cache || {};
return (param in cache) ? cache[param] : cache[param] = fib(param);
}
// stoyan's memoizer
function memoize3(param) {
if (!memoize3.cache) {
memoize3.cache = {};
}
if (!memoize3.cache[param]) {
var result = fib(param); //custom function
memoize3.cache[param] = result;
}
return memoize3.cache[param];
}
//latest gratest sept 9th 2014 memoize.js
var memoize4 = function(func) {
var stringifyJson = JSON.stringify,
cache = {};
var cachedfun = function() {
var hash = stringifyJson(arguments);
return (hash in cache) ? cache[hash] : cache[hash] = func.apply(this, arguments);
};
cachedfun.__cache = (function() {
cache.remove || (cache.remove = function() {
var hash = stringifyJson(arguments);
return (delete cache[hash]);
});
return cache;
}).call(this);
return cachedfun;
};
var memoize5 = underscore.memoize;
var memoize6 = lodash.memoize;
var memoize7 = lodashLatest.memoize;
var m1, m2, m3, m4, m5, m6, m7 = 0;
</script>
Ready to run.
Test | Ops/sec | |
---|---|---|
Compact memoize.js |
| ready |
Stoyan's version |
| ready |
With external cache |
| ready |
memoize.js (fn) |
| ready |
underscore (fn) |
| ready |
lodash (fn) |
| ready |
lodash latest (fn) |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.