Underscore.each vs jQuery.each vs. for loop vs. nimble-foreach (v135)

Revision 135 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,
      a = "t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t".split(","),
      e;
</script>

Test runner

Ready to run.

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

Revisions

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