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

Revision 87 of this benchmark created on


Preparation HTML

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js">
</script>
<script src="//documentcloud.github.com/underscore/underscore-min.js">
</script>
<script>
  var pi = Math.PI;
  var e;
  var o = {};
  for(var i = 0; i < 10000; i++) {
    o["object" + i] = i;
  }
</script>

Test runner

Ready to run.

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

Revisions

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