for vs forEach (v308)

Revision 308 of this benchmark created on


Description

Is it faster to use the native forEach or just loop with for?

Setup

var i, values = [],
          sum = 0;
      for (i = 0; i < 100000; i++) {
       values[i] = i;
      }

Test runner

Ready to run.

Testing in
TestOps/sec
forEach
values.forEach(function(val) {
sum += val;
});
ready
for loop, simple
var len = values.length;
for (i = 0; i < len; i++) {
 sum += values[i];
}
ready
for of
for(var val of values) {
sum += val;
}
ready

Revisions

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