for vs. jQuery.each vs. forEach (v2)

Revision 2 of this benchmark created by Martijn on


Preparation HTML

<script src='//code.jquery.com/jquery-latest.min.js'></script>
<script>
  var arr = ['a', 'b', 'c'];
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
for loop
for (var i = 0; i < arr.length; i++) {
 i + ': ' + arr[i];
}
ready
jQuery.each
$.each(arr, function(i, v) {
 i + ': ' + v;
});
ready
forEach
arr.forEach(function(v, i) {
 i + ': ' + v;
});
ready
for loop, cached length
for (var i = 0, l = arr.length; i < l; i++) {
 i + ': ' + arr[i];
}
ready

Revisions

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