Performance of Array vs. Object

JavaScript performance comparison

Revision 105 of this test case created by

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  var arr = [],
      i,
      obj = {};
  for(i = 0; i < 10000; i += 1) {
      obj[i] = {body:'aaa',};
      arr.push({
          id: i,
          body:'aaa',
      });
  }
  

};
</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 Performance
var id = 10000,
    body;
for (var x=0, current; x< id; x++) {
    current = arr[x];
    if (current.id === id) {
        body = current.body;
        break;
    }
}
pending…
Object Performance
var body = obj['10000'];
pending…
Object Performance using known length
pending…
Using Object.keys()
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