array vs obj for access number key

JavaScript performance comparison

Test case created by Liam Mitchell

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var a = [{
      value: 1
    }, {
      value: 2
    }, {
      value: 3
    }, {
      value: 4
    }, {
      value: 5
    }];
    var b = {
      0: {
        value: 1
      },
      1: {
        value: 2
      },
      2: {
        value: 3
      },
      3: {
        value: 4
      },
      4: {
        value: 5
      }
    }
};
</script>

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
a
for (var i = 0; i < 5; i++) {
  a[i].value * 10;
}
pending…
b
for (var i = 0; i < 5; i++) {
  b[i].value * 10;
}
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

Add a comment