Performance of Array vs. Object (v31)

Revision 31 of this benchmark created on


Setup

var arr = [],offset = 89,len = 100,
      i, obj = {};
  for (i = 0; i < len ; i += 1) {
    var o = {
      i: i
    };
    arr.push(o);
    obj[i] = i;
  }

Test runner

Ready to run.

Testing in
TestOps/sec
Array Performance
var sum = 0;
for (var x = 0; x < arr.length; ++x) {
  if (x == offset ) {
    console.log(arr[x]);
    break;
  }
}
ready
Object Performance
console.log(obj[offset])
ready
Object Performance using known length
var sum = 0;
for (var x = 0; x < len ; ++x) {
  if (x == offset ) {
    console.log(arr[x]);
    break;
  }
}
ready

Revisions

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