Array Performance

JavaScript performance comparison

Revision 60 of this test case created by

Preparation code

  Benchmark.prototype.setup = function() {

    //Using an object constructor will make the calculations go faster in chromes v8 engine
    function userConstructor (id, name1) { = id;
        this.name1 = name1;

    //Cached to speed up the object constructor as we are testing lookup speed not the constructor speed.
    var name1 = 'Some Random Name';

    var a1 = [new userConstructor(29938, name1),
              new userConstructor(32994, name1),
              new userConstructor(54235, name1),
              new userConstructor(43412, name1),
              new userConstructor(21346, name1)

    var a2 = [];
    a2[29938] = new userConstructor(29938, name1);
    a2[32994] = new userConstructor(32994, name1);
    a2[54235] = new userConstructor(54235, name1);
    a2[43412] = new userConstructor(43412, name1);
    a2[21346] = new userConstructor(21346, name1);

    var o = {};
    o['29938'] = new userConstructor(29938, name1);
    o['32994'] = new userConstructor(32994, name1);
    o['54235'] = new userConstructor(54235, name1);
    o['43412'] = new userConstructor(43412, name1);
    o['21346'] = new userConstructor(21346, name1);

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
function getNameById(id) {
  for (var i = 0; i < a1.length; i++) {
    if (a1[i].id === id) {
      return a1[i].name1;

var id = 21346;
var result = getNameById(id);
Holey Array by Index
var id = 21346;
var result = a2[id];
Object by Key
var id = '21346';
var result = o[id];

Compare results of other browsers


You can edit these tests or add even more tests to this page by appending /edit to the URL.