For vs forEach (v216)

Revision 216 of this benchmark created by Dave Hulme on


Description

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

Setup

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

Test runner

Ready to run.

Testing in
TestOps/sec
forEach
values.forEach(function(value) {
  
});
ready
for loop
var i;
for (i = 0; i < values.length; i++) {
  var value = values[i];
}
ready

Revisions

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