Array Performance (v120)

Revision 120 of this benchmark created on


Description

Manual array lookups vs. holey arrays.

Setup

var a1 = [{id: "ffddgh", name: 'name1'}, {id: "asdfgh", name: 'name1'}];

    var a2 = [];
    a2["ffddgh"] = {id: "ffddgh", name: 'name1'};
    a2["asdfgh"] = {id: "asdfgh", name: 'name1'};

    var o = {};
    o["ffddgh"] = {id: "ffddgh", name: 'name1'};
    o["asdfgh"] = {id: "asdfgh", name: 'name1'};

Test runner

Ready to run.

Testing in
TestOps/sec
Manual Array Lookup
var id = "ffddgh";
for (var i = 0; i < a1.length; i++) {
  if (a1[i].id = id) result = a1[i];
}
 
ready
Holey Array by Index
var id = "ffddgh";
var result = a2[id];
ready
Object by Key
var id = "ffddgh";
var result = o[id];
 
ready

Revisions

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