nested property lookup, cached or not

Benchmark created by Kyle Simpson on


Description

Testing/profiling the code patterns from the Script Junkie article "(pre)Maturely Optimize Your JavaScript"

http://msdn.microsoft.com/en-us/scriptjunkie/gg622887.aspx

Snippet comparison #6

Preparation HTML

<script>
  var foo = {
   bar: {
    baz: {
     fun: "weee!"
    }
   }
  },
      _fun = foo.bar.baz.fun,
      res;
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
full property lookup
res = "";

for (var i = 0; i < 1000; i++) {
 res += foo.bar.baz.fun[i % foo.bar.baz.fun.length]; // not using the cached property lookup
}
ready
cached property lookup
res = "";

for (var i = 0; i < 1000; i++) {
 res += _fun[i % _fun.length]; // using the cached property lookup
}
ready

Revisions

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

  • Revision 1: published by Kyle Simpson on
  • Revision 2: published by redsquare on
  • Revision 3: published by redsquare on
  • Revision 4: published by redsquare on
  • Revision 6: published by js user on
  • Revision 7: published on
  • Revision 8: published by sansegot on