Performance of Array vs. Object (v175)

Revision 175 of this benchmark created on


Setup

var arr = [],
      i,
      obj = {},
      m = new Map
  ;
  for(i = 0; i < 10000; i += 1) {
      var o = {payload:i};
      arr.push(o);
      obj[i] = o;
      m.set(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 = arr.length;
while (i > 0) {
    i--;
    sum += m.get(arr[i].payload).payload;
}
ready

Revisions

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