Underscore.each vs jQuery.each vs. for loop vs. forEach (v290)

Revision 290 of this benchmark created by nomiadcode on


Preparation HTML

<script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>
</script>
<script src="//documentcloud.github.com/underscore/underscore-min.js">
</script>
<script>
  var pi = Math.PI
  var a = new Array(1000000),
      e;
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
jQuery.each
$.each(a, function(value,index) {
  e = pi;
});
ready
good old for loop
var value;
for (var i = 0, len = a.length; i < len; i++) {
  value=a[i];
  e = pi;
};
ready
underscore.each
_.each(a, function(value,index) {
  e = pi;
});
ready
good old for loop (decrementing)
var i = a.length;
var value;
for (; i > 0; i--) {
  value=a[i];
  e = pi;
};
ready
forEach
a.forEach(function(value,index) {
  e = pi;
})
ready

Revisions

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