Underscore.each vs jQuery.each vs. for loop (v200)

Revision 200 of this benchmark created on


Description

updated to remove the possibility that things are just getting optimized to oblivion.

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 a = new Array(10000),
      e;
  for (var i = 0; i < a.length; i++) a[i] = i;
</script>

Test runner

Ready to run.

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

Revisions

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