Comparison of property lookup approaches

Benchmark created by Addy Osmani on


Preparation HTML

<script>
  /*just a sample function so we have something custom properties can be attached to*/
  function getValue(value){
    return value;
  }
  
  var cache = {};
  getValue.cache = {};
  
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
Custom function property
getValue.prop = 5;
getValue(getValue.prop); //lookup
ready
Separate variable
cache.prop = 5;
getValue(cache.prop);
ready

Revisions

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

  • Revision 1: published by Addy Osmani on
  • Revision 2: published by Digitale Welten on
  • Revision 5: published by Digitale Welten on
  • Revision 6: published by Digitale Welten on