Underscore.each vs jQuery.each vs. for loop vs. forEach vs. LoDash each (v259)

Revision 259 of this benchmark created on


Preparation HTML

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/underscore.js/1.4.4/underscore-min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/lodash.js/1.3.1/lodash.min.js"></script>
<script>
  var lodash = _.noConflict();
  var pi = Math.PI
  var a = new Array(1000),
      e;
function addit() {e+=pi};
</script>

Setup

var $ = window.$;
    var underscore = window._;
    var lodash = window.lodash;
    
    var e;
    var array = window.array;

Test runner

Ready to run.

Testing in
TestOps/sec
jQuery.each
$.each(a, addit);
ready
good old for loop
for (var i = 0, len = a.length; i < len; i++) {
  addit();
}
ready
underscore.each
underscore.each(a, addit);
ready
good old for loop (decrementing)
var i = a.length;
while (i--) {
  addit();
}
ready
forEach
a.forEach(addit);
ready
map?
a.map(addit);
ready
for function
var i = a.length;
for (; i > 0; i--) {
  addit();
}
ready
dumb for loop
for (var i = 0, len = a.length; i < len; i++) {
  addit();
}
ready
lodash
lodash.each(a, addit);
ready
another for loop
for (var i = 0; i < a.length; i++) {
  addit();
}
ready
another for loop 2
for (var i = 0; i < a.length; i-=-1) {
  addit();
}
ready
another for loop 3
for (var i = 0; i < a.length; i+=1) {
  addit();
}
ready

Revisions

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