Collection performance

Benchmark created by Adam on


Description

Testing lodash vs underscore vs native iterating over a collection of objects.

Preparation HTML

<script src="https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.8.3/underscore-min.js"></script>
<script>
var underscore = _.noConflict();
</script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/3.6.0/lodash.min.js"></script>
<script>
var lodash = _.noConflict();
</script>

Setup

var DATA = [];
    
    lodash.fill(DATA, {
      foo: 'bar',
      baz: new Date()
    }, 0, 10);
    
    function randomData(id) {
      return id * Math.floor(Math.random() * 1000)
    }

Test runner

Ready to run.

Testing in
TestOps/sec
native for loop
for (var i = 0, il = DATA.length; i < il; ++i) {
  var item = DATA[i];
  item.id = randomData(i);
}
ready
native forEach
DATA.forEach(function(item, index) {
  item.id = randomData(index);
});
ready
lodash.each
lodash.each(DATA, function(item, index) {
  item.id = randomData(index);
});
ready
underscore.each
underscore.each(DATA, function(item, index) {
  item.id = randomData(index);
});
ready

Revisions

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