Jquery each vs Underscore each vs For loops (v55)

Revision 55 of this benchmark created on


Preparation HTML

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js">
</script>
<script src="https://raw.github.com/lodash/lodash/3.1.0/lodash.js"></script>
var lodash = _.noConflict();
<script src="http://underscorejs.org/underscore-min.js">
</script>

Setup

var arr = [];
    for (var i = 0; i < 10000; i++) {
      arr.push({
        Number: i
      });
    };
    var e = null;
    
    function Named(o, i) {
      e = o;
    };

Test runner

Ready to run.

Testing in
TestOps/sec
Jquery each
$.each(arr, function(i, o) {
  e = o;
});
ready
Underscore each
_.each(arr, function(o, i) {
  e = o;
});
ready
For normal
for (var i = 0, len = arr.length; i <= len; i++) {
  e = arr[i];
};
ready
For reversed
for (var l = arr.length; l >= 0; l--) {
  e = arr[l];
};
ready
Native array forEach
if (arr.forEach) {
  arr.forEach(function(o, i) {
    e = o;
  });
};
ready
Native array forEach with Named function
if (arr.forEach) {
  arr.forEach(Named);
};
ready
For in loop
for (var i in arr) {
  e = arr[i];
};
ready
lodash each
lodash.each(arr, function(i, o) {
  e = o;
});
ready

Revisions

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