Performance of Array vs. Object

JavaScript performance comparison

Revision 130 of this test case created by and last updated

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  var arr = [],
      i,
      obj = { array:[] };
  
  for(i = 0; i < 10; i++) {
      arr.push(i);
      obj.array.push(i);
  }
  

};
</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 i = 0; i < arr.length; i++){
arr[i] = i;
};
pending…
Object Performance
for(var i = 0; i < arr.length; ++i){
arr[i] = i;
};
pending…
Object Performance using known length
var x = arr.length;
while(--x){
arr[x] = x;
};
pending…
Using Object.keys()
var x = obj.array.length;
while(--x){
obj.array[x] = x;
};
pending…
Array Performance known length
var x = 0;
while(++x < obj.array.length){
obj.array[x] = x;
};
pending…
Array using .foreach
for(var i = 0; i < obj.array.length; i++){
obj.array[i] = 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