bracket vs dot

Benchmark created on


Setup

// Setup
const iterations = 1000000;

// Create a deep prototype chain
const proto1 = { deepProp: 1 };
const proto2 = Object.create(proto1);
proto2.midProp = 2;
const obj = Object.create(proto2);
obj.ownProp = 3;

Test runner

Ready to run.

Testing in
TestOps/sec
// Test accessing own property with dot notation

// Test accessing own property with dot notation
function ownPropertyDotTest() {
  let sum = 0;
  for (let i = 0; i < iterations; i++) {
    sum += obj.ownProp;
  }
  return sum;
}
ready
// Test accessing own property with bracket notation
function ownPropertyBracketTest() {
  let sum = 0;
  for (let i = 0; i < iterations; i++) {
    sum += obj['ownProp'];
  }
  return sum;
}
ready
// Test accessing mid-level prototype property with dot notation
function midProtoDotTest() {
  let sum = 0;
  for (let i = 0; i < iterations; i++) {
    sum += obj.midProp;
  }
  return sum;
}
ready
// Test accessing mid-level prototype property with bracket notation
function midProtoBracketTest() {
  let sum = 0;
  for (let i = 0; i < iterations; i++) {
    sum += obj['midProp'];
  }
  return sum;
}
ready
// Test accessing deep prototype property with dot notation
function deepProtoDotTest() {
  let sum = 0;
  for (let i = 0; i < iterations; i++) {
    sum += obj.deepProp;
  }
  return sum;
}
ready
// Test accessing deep prototype property with bracket notation
function deepProtoBracketTest() {
  let sum = 0;
  for (let i = 0; i < iterations; i++) {
    sum += obj['deepProp'];
  }
  return sum;
}
ready

Revisions

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