Array Performance

JavaScript performance comparison

Revision 124 of this test case created by

Preparation code

<script>
  Benchmark.prototype.setup = function() {
    var a1 = new Array();

    for (var i = 0; i < 2000; i+=2) {
       a1.push({id: i, name: 'name1'});
    }

    var a2 = new Array();
    for (var i = 0; i < 2000; i+=2) {
       a2[i] = {id: i, name: 'name1'};
    }

    var o = {};
    for (var i = 0; i < 2000; i+=2) {
       o[i] = {id: i, name: 'name1'};
    }
  };
</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
Manual Array Lookup
for (var i = 0; i < 2000; i+=2) {
  var result;
  for (var f = 0; f < a1.length; f++) {
    if (a1[f].id == i) {
      result = a1[f];
      break;
    } 
  }     
}
pending…
Holey Array by Index
var result;
for (var i = 0; i < 2000; i+=2) {
  result = a2[i];      
}
pending…
Object by Key
var result;
for (var i = 0; i < 2000; i+=2) {
  result = o[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