foreach vs each

Benchmark created by foreach vs each on


Preparation HTML

<script>
  var arr = [1,2,3,4,5,6,7,8,9,10];
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
foreach
var o = 0;
arr.forEach(function(v) {
 o += v;
});
ready
each
var o = 0;
for (var i = 0, ii = arr.length; i < ii; i++) {
 o += arr[i];
}
ready

Revisions

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