forEach vs loop (v103)

Revision 103 of this benchmark created by Devin Jett on


Description

Better test body

Setup

var arr = [];
    for (var i = 0; i < 50; 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++) {
  sum += arr[i];
}
ready

Revisions

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