for vs. jQuery.each vs. forEach

Benchmark created 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

Revisions

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