Performance of Array vs. Object (v212)

Revision 212 of this benchmark created on


Description

\

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
var string = 'x'.repeat(10);
console.log(obj[string]);
ready

Revisions

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