for vs forEach (v270)

Revision 270 of this benchmark created by Tahar on


Description

Is it faster to use forEach with a function as parameter?

Preparation HTML

<script>
  var i, values = [],sum = 0;
  for (i = 0; i < 10000; i++) {
   values[i] = i;
  }
  
  function add(val) {
   sum += val;
  }
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
foreach loop with a function reference
values.forEach(add);
ready
foreach loop with a function parameter
  values.forEach(function(val) {
   sum += val;
  });
ready

Revisions

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