Jquery each vs Underscore each vs For loops (v32)

Revision 32 of this benchmark created on


Preparation HTML

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js">
</script>
<script src="http://documentcloud.github.com/underscore/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;
    };
    
    function Name2(i, o) {
      e = o;
    };
    var forEach = function(a, c) {
      for (var i = a.length - 1; i >= 0; i--) c(a[i], i)
    }
    var forEac2 = function(a, c) {
      "use asm";
      var l = +a.length;
      for (var i = +0; i < l; i++) c(a[i], i)
    }

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
arr.forEach(function(o, i) {
  e = o;
});
ready
Native array forEach with Named function
arr.forEach(Named);
ready
custom forEach
forEach(arr, function(o, i) {
  e = o;
});
ready
custom forEach 2
function it(o, i) {
  e = o;
}
forEach(arr, it);
ready
custom forEach Named
forEach(arr, Named)
ready
Jquery each Named
$.each(arr, Name2);
ready
Underscore each Named
$.each(arr, Named);
ready
For normal Named
for (var i = 0, l = arr.length; i <= l; i++) Named(arr[i], i);
ready
custom forEach asm.js Named
forEac2(arr, Named)
ready
custom forEach asm.js
function it(o, i) {
  e = o;
}
forEac2(arr, it)
ready

Revisions

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