Array loop vs object loop lookup

JavaScript performance comparison

Test case created by Sukima

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  var the_array, the_object, i, len, result;
  
  the_array = [];
  the_object = {};
  
  for (i = 0; i< 10000; i++) {
    the_array.push("foobar");
    the_object["" + i] = "foobar";
  }

};
</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
Arrays
for (i = 0, len = the_array.length; i < len; i++) {
  result = the_array[i];
}
pending…
Objects
for (i in the_object) {
  result = the_object[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