Function Caching (v2)

Revision 2 of this benchmark created on


Description

A quick test to see if some sort of caching of function results can improve performance.

Preparation HTML

<script>
  // Normally I'd wrap this in an anonymous function.
  var _cache = {};
  
  function CacheTest(a, b) {
   if (!_cache[result]) {
    var result = a + b;
    _cache[result] = result;
   }
  
   return _cache[result];
  }
  
  function NoCacheTest(a, b) {
   return a + b;
  }
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
Cached Test
CacheTest(5, 5);
ready
Not Cached Test
NoCacheTest(5, 5);
ready

Revisions

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