forEach vs loop (v119)

Revision 119 of this benchmark created on


Description

Better test body

Setup

var arr = [];
    for (var i = 0; i < 500000; i++) arr[i] = i;
    var sum = 0;
    var fn = function(v) {
      sum += v;
    }

Test runner

Ready to run.

Testing in
TestOps/sec
forEach
arr.forEach(fn);
ready
loop
for (var i = 0, l = arr.length; i < l; i++) {
  if (arr[i]) sum += arr[i];
}
ready

Revisions

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