Array Performance (v64)

Revision 64 of this benchmark created on


Description

Manual array lookups (array scans) vs. holey arrays vs. array lookups by index vs. object lookups.

Base test case: revision 29.

Changes:

  • Rename "Object by Key String" to "Object by Key String (dynamic)" to emphasize artificial .toString() cost.
  • Add test "Object by Key String (static)" that removes artificial .toString() cost from "Object by Key String (dynamic)".

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 (dynamic)
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
Object by Key String (static)
var id = "30000", result = O1[id];
ready

Revisions

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