.(dot) vs [](square bracket) (v5)

Revision 5 of this benchmark created by Michael Norman on


Preparation HTML

<script>
  var doc = "document";
  
  // setup a tiny object
  var foo = {
   bar: "value"
  };
  var baz = "bar";
  
  // setup a really big object
  var bigObj = {};
  for (var i = 0; i < 100000; i++) {
   bigObj["prop" + i] = "value" + i;
  }
  
  var bigObjPropName = "prop25";
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
window dot
var a = window.document;
ready
window bracket with literal
var a = window["document"];
ready
window bracket with variable
var a = window[doc];
ready
foo dot
var a = foo.bar;
ready
foo bracket with literal
var a = foo["bar"];
ready
foo bracket with variable
var a = foo[baz];
ready
bigObj dot
var a = bigObj.prop25;
ready
bigObj bracket with variable
var a = bigObj[bigObjPropName];
ready

Revisions

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

  • Revision 1: published by JavaScript Nazi on
  • Revision 2: published by Kyle Simpson on
  • Revision 5: published by Michael Norman on
  • Revision 6: published by blocks-vs-functions on
  • Revision 7: published on
  • Revision 8: published by mah0x211 on
  • Revision 9: published by mah0x211 on
  • Revision 13: published on
  • Revision 15: published on
  • Revision 18: published by foo on