Array Performance

JavaScript performance comparison

Revision 288 of this test case created by

Preparation code

<script>
  Benchmark.prototype.setup = function() {
    var counter = 10000;
    var step = 4

    var rawKey = Math.round(counter * Math.random());
    var key = rawKey - rawKey % step;
    var classicKey = key / step;

    var a1 = [];
    var a2 = [];
    var o = {};
    for (var i = 0; i < counter; i += step) {
        var pair = { key: i, value: "value" + i };
        a1.push(pair);
        a2[i] = pair;
        o[i] = pair;
    }
  };
</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
Manual Array Lookup
for (var i = 0; i < a1.length; i++) {
  if (a1[i].key === key) {
    result = a1[i];
    break;
  }
}
pending…
Manual Object Lookup
for (var i = 0; i < o.length; i++) {
  if (o[i].key === key) {
    result = o[i];
    break;
  }
}
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