for vs forEach (v271)

Revision 271 of this benchmark created on


Preparation HTML

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

Test runner

Ready to run.

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

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.