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 memoizeMap(func, resolver) {
let cache = new Map();
return function (...args) {
const key = resolver ? resolver.apply(this, args) : args[0];
if (cache.has(key)) {
return cache.get(key);
}
const result = func.apply(this, args);
cache = cache.set(key, result) || cache;
return result;
};
}
function memoizeWeakMap(func, resolver) {
let cache = new WeakMap();
return function (...args) {
const key = resolver ? resolver.apply(this, args) : args[0];
if (cache.has(key)) {
return cache.get(key);
}
const result = func.apply(this, args);
cache = cache.set(key, result) || cache;
return result;
};
}
function memoizeSimon(fn) {
const memo = new Map();
return function (...x) {
const key = JSON.stringify(x);
return memo.set(key, memo.has(key) ? memo.get(key) : fn(...x)).get(key);
};
}
const obj = { foo: 12, baz: 12 };
</script>
Ready to run.
Test | Ops/sec | |
---|---|---|
using memoize |
| ready |
using simons memoize |
| ready |
using weakmap |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.