Performance of Array vs. Object (v176)

Revision 176 of this benchmark created on


Setup

var arr = [],
      i,
      obj = {},
      index = [],
      m = new Map
  ;
  for(i = 0; i < 10000; i += 1) {
      var o = {payload:i};
      arr.push(o);
      obj[i] = o;
      index[i] = String(i);
      m.set(String(i), o);
  }

Test runner

Ready to run.

Testing in
TestOps/sec
Array Performance
var sum = 0;
for (var x=0; x<arr.length; ++x) {
    sum += arr[x].payload
}
ready
Object Performance
var sum = 0;
for (var x in obj) {
    sum += obj[x].payload;
}
ready
Object Performance using known length
var sum = 0;
for (var x=0; x<10000; ++x) {
    sum += obj[x].payload
}
ready
Using array as index to map
var sum = 0;
var i = index.length;
while (i > 0) {
    i--;
    sum += m.get(index[i]).payload;
}
ready

Revisions

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