array vs object

JavaScript performance comparison

Test case created by Abraham

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  var arr = [],
    i,
    obj = {};
    for(i = 0; i < 100; i = i + 1) {
      var item = {index: i};
      arr.push(item);
      obj[i] = item;
    }

};
</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
for (var x=0; x<arr.length; x++) {
    i = arr[x].index;
}
pending…
object
for (var x=0; x<100; x++) {
    i = obj[x].index;
}
pending…
object unknown length
var keys = Object.keys(obj);
for (var x = 0; x < keys.length; x++){
  i = obj[keys[x]].index;
}
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