object literal treated as array

JavaScript performance comparison

Test case created by Eric Burley

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
   var a = {},
     b = []
     i = 0;
  
   // init a 5000 element object and 5000 element array
   for (; i < 5000; i++) {
     a[i] = i;
   }
   for (i = 0; i < 5000; i++) {
     b[i] = i;
   }

};

Benchmark.prototype.teardown = function() {
  a = b = null;
  i = 0;

};
</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
push/pop 100 elements on a 5000 element object
var x = 0;
for (x = 0; x < 100; x++) {
  Array.prototype.push.call(a, x);
}
for (; x > 0; x--) {
  Array.prototype.pop.call(a);
}
pending…
push/pop 100 elements on a 5000 element array
var x = 0;
for (x = 0; x < 100; x++) {
  b.push(x);
}
for (; x > 0; x--) {
  b.pop();
}
pending…

You can edit these tests or add even more tests to this page by appending /edit to the URL.

Compare results of other browsers

0 Comments