Array.forEach vs. jQuery.each

Benchmark created on


Preparation HTML

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script>
  var arr = [],
      i = 100;
  while (i--) {
   arr.push(Math.random());
  }
  var sum;
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
jQuery#each
sum = 0;
$.each(arr, function(i, elem) {
 sum += elem;
});
ready
Array#forEach
sum = 0;
arr.forEach(function(elem) {
 sum += elem;
});
ready

Revisions

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