Lo-Dash each vs Underscore each vs Native forEach (v5)

Revision 5 of this benchmark created by Christian Oestreich on


Description

Comparing apples to apples in function body

Preparation HTML

<script src="//cdnjs.cloudflare.com/ajax/libs/underscore.js/1.4.1/underscore-min.js">
</script>
<script src="//cdnjs.cloudflare.com/ajax/libs/lodash.js/0.8.2/lodash.min.js">
</script>
<script>
  var lodash = _.noConflict();
  var pi = Math.PI,
      a = "t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t".split(","),
      e;

var cb = function(item) {
    item = pi;
    };
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
Lo-Dash each
lodash.each(a, function(item) {
  cb(item);
});
ready
Underscore each
_.each(a, function(item) {
    cb(item);
});
ready
Native forEach
a.forEach(function(item) {
    cb(item);
});
ready
Native for
for (var ix = 0, len = a.length; ix < len; ix++) {
  cb(a[ix]);
}
ready
Native forEach v2
a.forEach(cb);
ready
Wrapped native for
var _ = {
  each: function(xs, f) {
    var key, value, _results;
    _results = [];
    for (key in xs) {
      value = xs[key];
      _results.push(f(key, value));
    }
    return _results;
  }
};
_.each(a, cb)
ready
Native for dynamic length
for (var ix = 0; ix < a.length; ix++) {
  cb(a[ix]);
}
ready

Revisions

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