array-lookup-vs-object-lookup

JavaScript performance comparison

Revision 4 of this test case created by

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  var o = Object.create(null);
  var a = [];
  
  for(var i = 0; i <= 1000; i+=0.1){
    o[''+i] = {};
    a[''+i] = [];
    for(var j = 0; j <= 1000; j+=0.1){
      o[''+i][''+j] = 'p'+i;
      a[''+i][''+j] = ('p'+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
var p;
for(var i = 0; i <= 1000; i+=0.1){
  for(var j = 0; j <= 1000; j+=0.1){
  p = a[''+i][''+j];
  }
}
pending…
Object
var p;
for(var i = 0; i <= 1000; i+=0.1){
  for(var j = 0; j <= 1000; j+=0.1){
  p = o[''+i][''+j];
  }
}
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