Array Performance (v29)

Revision 29 of this benchmark created by David Bonnet on


Description

Manual array lookups vs. holey arrays.

Setup

A1 = [];
    O1 = {};
    var amount=50000;
    for (var i=0; i < amount; i++) {
      A1.push({id: i, name: 'name1'});
      O1[''+i] = {id: i, name: 'name1'};
    }

    A2 = [];
    A2[20000] = {id: 20000, name: 'name1'};
    A2[30000] = {id: 30000, name: 'name1'};

    A3 = [{id: 20000, name: 'name1'}, {id: 30000, name: 'name1'}];

Test runner

Ready to run.

Testing in
TestOps/sec
Manual Array Lookup
var id = 30000, result, a = A1, l = a.length;
for (var i = 0; i < l; i++) {
  if (a[i].id == id) {
    result = a[i];
    break;
  }
}
ready
Holey Array by Index
var id = 30000, result = A2[id];
ready
Object by Key String
var id = 30000, result = O1[id.toString()];
ready
Manual Array Lookup (small)
var id = 30000, result, a = A3, l = a.length;
for (var i = 0; i < l; i++) {
  if (a[i].id == id) {
    result = a[i];
    break;
  }
}
ready
Object by Key Index
var id = 30000, result = O1[id];
ready
Array by Index
var id = 30000, result = A1[id];
ready

Revisions

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