Performance of Array vs. Object

JavaScript performance comparison

Revision 16 of this test case created by

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  var arr = [],
      obj_arr = [],
      obj = {},
      obj_obj = {},
      i,
      times = 1000;
  
  for(i = 0; i < times; i+=1) {
      arr.push(i);
      obj[i] = i;
      obj_arr[i] = {v: 1};
      obj_obj[i] = {v: 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
for (var x=0; x<arr.length; x+=1) {
    arr[x]
}
pending…
Object Performance
for (var x in obj) {
    obj[x]
}
pending…
Object Performance using known keys
for (var x=0; x<times; x+=1) {
    obj[x]
}
pending…
Array of objects Performance
for (var x=0; x<obj_arr.length; x+=1) {
    obj_arr[x]
}
pending…
Object of objects Perfomance
for (var x=0; x<times; x+=1) {
    obj_obj[x]
}
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