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

Revision 9 of this benchmark created on


Description

Comparing apples to apples in function body

Preparation HTML

<script src="//cdnjs.cloudflare.com/ajax/libs/lodash.js/1.3.1/lodash.compat.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,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,tt,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,tt,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,tt,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>
<script src="//cdnjs.cloudflare.com/ajax/libs/underscore.js/1.4.4/underscore-min.js">
</script>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></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(function(item) {
  cb(item);
});
ready
Native for dynamic length
for (var ix = 0; ix < a.length; ix++) {
  cb(a[ix]);
}
ready
jquery each
$.each(a, function(item) {
  cb(item);
});
ready

Revisions

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