Array Performance

JavaScript performance comparison

Revision 327 of this test case created by

Preparation code

<script>
  Benchmark.prototype.setup = function() {
    var N = 10000, M = 10000;
    var arr = [], obj = {}, rnd = [], str = '';
    for( var i = 0; i <= N; i++) {
      str += 'x';
      arr.push( { id: i, name: str });
      obj[i] = { id: i, name: str };
    }
    for( var i = 0; i < M; i++) {
      rnd.push(Math.floor(Math.random()*N));
    }
  };
</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
var result = 0;
for (var i = 0; i < rnd.length; i++) {
  var x = obj[rnd[i]];
  result += x.id + x.name.length;
}
pending…
Array
var result = 0;
for (var i = 0; i < rnd.length; i++) {
  var x = arr[rnd[i]];
  result += x.id + x.name.length;
}
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