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

Revision 18 of this benchmark created by foo 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;
  }
  //add symbols if supported (don't break non supporting browsers)
  if(typeof Symbol !== "undefined") {
      var sym = Symbol("sym");
      bigObj[sym] = 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
bigObj literal
var a = bigObj["prop25"];
ready
foo bracket with local variable
var prop = "bar";
var a = foo[prop];
ready
foo bracket with const var
const prop = "bar";
var a = foo[prop];
ready
bigObj bracket with local var
var prop = "prop25";
var a = bigObj[prop];
ready
bigObj with Symbol
var a = bigObj[sym];
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