Performance of Array vs. Object (v211)

Revision 211 of this benchmark created on


Setup

var arr = [],
    i,
    obj = {};
  obj.length = 0;
  for (i = 0; i < 10000; i += 1) {
    var string = 'x'.repeat(i);
    var o = {
      payload: string
    };
    arr.push(o);
    obj[string] = o;
    obj.length += 1;
  }

Test runner

Ready to run.

Testing in
TestOps/sec
Array Performance
var string;
var test = 'x'.repeat(10);
for (var x = 0; x < arr.length; ++x) {
  if (arr.payload === 'x'.repeat(10)) {
    string = arr.payload;
    break;
  }
}
console.log(string);
ready
Object Performance
console.log(obj['x'.repeat(10)]);
ready

Revisions

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