Performance of Array vs. Object

JavaScript performance comparison

Revision 212 of this test case created by

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  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;
  }

};
</script>

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/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);
pending…
Object Performance
var string = 'x'.repeat(10);
console.log(obj[string]);
pending…

Compare results of other browsers

Revisions

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

0 Comments