wat2

Benchmark created on


Preparation HTML

<script>
function memoizeMap(func, resolver) {
  let cache = new Map();

  return function (...args) {
    const key = JSON.stringify(args);

    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>

Test runner

Ready to run.

Testing in
TestOps/sec
using memoize
memoizeMap(Object.entries)(obj);
ready
using simons memoize
memoizeSimon(Object.entries)(obj);
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.