Tests:
  • Memoizer

    x
     
    function memoizer(func) {
      const cache = {};
      return function() {
        const key = JSON.stringify(arguments);
        if (cache[key] !== undefined) {
          return cache[key];
        }
        const result = func(...arguments);
        cache[key] = result;
        return result;
      };
    }
    const fibonacci = n => {
      if (n <= 1) return 1;
      return fibonacci(n - 1) + fibonacci(n - 2);
    };
    const cachedFibonacci = memoizer(fibonacci);
    const getCachedFibonacci = (limit = 1) => {
      const arr = [];
      for (let i = 0; i <= limit; i++) {
        arr.push(cachedFibonacci(i));
      }
      return arr;
    };
    getCachedFibonacci(30)
  • No Memoizer

     
    const fibonacci = n => {
        if (n <= 1) return 1;
        return fibonacci(n - 1) + fibonacci(n - 2);
    };
    const getFibonacci = (limit = 1) => {
        const arr = [];
        for (let i = 0; i <= limit; i++) {
            arr.push(fibonacci(i));
        }
        return arr;
    };
    getFibonacci(30)
Rendered benchmark preparation results:

Suite status: <idle, ready to run>

Previous results

Experimental features:

  • Test case name Result
    Memoizer
    No Memoizer

    Fastest: N/A

    Slowest: N/A

Latest run results:
Run details: (Test run date: 4 years ago)
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.75 Safari/537.36
Chrome 86 on Mac OS X 10.15.7
View result in a separate tab
Test name Executions per second
Memoizer 17.2 Ops/sec
No Memoizer 17.2 Ops/sec