Jquery each vs Lodash each vs For loops (v61)

Revision 61 of this benchmark created by Joshua Koudys on


Preparation HTML

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js">
</script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/3.5.0/lodash.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;
    };
    
    var forEach = function (array, callback, scope) {
      for (var i = 0; i < array.length; i++) {
        callback.call(scope, i, array[i]); // passes back stuff we need
      }
    };

Test runner

Ready to run.

Testing in
TestOps/sec
Jquery each
$.each(arr, function(i, o) {
  e = o;
});
ready
Lodash 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
  arr.forEach(function(o, i) {
    e = o;
  });
ready
Native array forEach with Named function
arr.forEach(Named);
ready
Lodash forEachRight
_.forEachRight(arr, function(o, i) {
  e = o;
});
ready
For normal supercache
var i, len = arr.length;
for (i = 0; i <= len; i++) {
  e = arr[i];
};
ready
For normal supercache reversed
var len = arr.length;
for (i = len; i >= 0; i--) {
  e = arr[i];
};
ready
User-defined forEach
forEach(arr, function(o, i) {
  e = o;
});
ready

Revisions

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