Array Performance

JavaScript performance comparison

Revision 326 of this test case created by

Preparation code

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