nested property lookup, cached or not (v6)

Revision 6 of this benchmark created by js user 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 baar = {
    foo: 'wooooh!'
  },
  _baar_foo = baar.foo;
  var foo = {
   bar: {
    baz: {
     fun: "weee!",
     foo: {
        wee:{
          too : "too"
        }
     }
    }
   }
  },
      _fun = foo.bar.baz.foo.wee.too,
      res;
</script>

Test runner

Ready to run.

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

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

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

for (var i = 0; i < 2; i++) {
 res += baar[i % baar.foo.length]; // using the cached property lookup
}
ready
one level cached
res = "";

for (var i = 0; i < 2; i++) {
 res += baar[i % _baar_foo.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