Performance of Array vs. Object

JavaScript performance comparison

Revision 111 of this test case created by

Preparation code

<script>
var arr = [],
    obj = {},
    i,
    len = 9001,
    sum;
for(i = 0; i < len; i += 1) {
    arr.push(i);
    obj[i] = i;
}
</script>
      
<script>
Benchmark.prototype.setup = function() {
  sum = 0;
  
  function add(x, y) {
  return x + y;
  }

};
</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
Object Performance using known length
for (i = 0; i < len; i += 1) {
  sum = add(sum, obj[i]);
}
pending…
Array Performance
for (i = 0; i < len; i += 1) {
  sum = add(sum, arr[i]);
}
pending…
Object Performance
for (i in obj) {
  sum = add(sum, obj[i]);
}
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