For vs forEach (v226)

Revision 226 of this benchmark created by Alexey 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;
    
    function callback(value) {}

Test runner

Ready to run.

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

Revisions

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