Array Performance (v74)

Revision 74 of this benchmark created on


Description

Manual array lookups vs. holey arrays.

Preparation HTML

<script src="https://raw.githubusercontent.com/lodash/lodash/2.4.1/dist/lodash.js"></script>

Setup

Benchmark.prototype.setup = function() {
    var a1 = [{id: '29938', name: 'name1'}, {id: '32994', name: 'name1'}];

    var a2 = [];
    a2[29938] = {id: 29938, name: 'name1'};
    a2[32994] = {id: 32994, name: 'name1'};

    var o = {};
    o['29938'] = {id: '29938', name: 'name1'};
    o['32994'] = {id: '32994', name: 'name1'};
  };
var id = '29938';
function func(val, i){
 //  if (val.id === id) 
  // result = val;
}

Test runner

Ready to run.

Testing in
TestOps/sec
Manual Array Lookup
for (var i = 0; i < a1.length; i++) {
  func(a1[i]);
}
 
ready
lodash
_.each(a1, function(val, i, arr) {
   func(val)
});
 
ready
var id = '29938';
var result = o[id];
 
ready
Native ForEach
a1.forEach(function(val) {
   func(val)
});
 
ready

Revisions

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