Array vs Object Performance

JavaScript performance comparison

Revision 325 of this test case created by

Preparation code

<script>
  Benchmark.prototype.setup = function() {
    var lookup = 0, lookupString = '';
    var i = 4000000;
    var id = 0;
    var a1 = [];
    var a2 = [];
    var o = {};
    var m = new Map();

    a1.length = 4000000;
    while (i--) {
        id = Math.floor(Math.random() * 100000);
        m.set(id, a1[i] = a2[id] = o[id + ''] = {id: id, name: 'name' + i});
    }

    lookup += a1[1500].id;
    lookupString += lookup;
  };
</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

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