Array Performance (v124)

Revision 124 of this benchmark created on


Description

Manual array lookups vs. holey arrays.

Setup

var a1 = new Array();

    for (var i = 0; i < 2000; i+=2) {
       a1.push({id: i, name: 'name1'});
    }

    var a2 = new Array();
    for (var i = 0; i < 2000; i+=2) {
       a2[i] = {id: i, name: 'name1'};
    }

    var o = {};
    for (var i = 0; i < 2000; i+=2) {
       o[i] = {id: i, name: 'name1'};
    }

Test runner

Ready to run.

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

Revisions

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