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

Revision 88 of this benchmark created by Juan Arribillaga 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
var i = 0,
    size = Object.keys(o).length;

for (i; i < size; ++i) {
  e = pi;
};
ready
underscore.each
_.each(o, function() {
  e = pi;
});
ready
good old for loop (with i++)
var i = 0,
    size = Object.keys(o).length;

for (i; i < size; i++) {
  e = pi;
};
ready

Revisions

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