for vs array-foreach (v11)

Revision 11 of this benchmark created by Kevin Chapelier on


Setup

var array = Array(1000).join('xxxxxxxx').split('');
    
    function callback(value, index, object) {
      return value;
    }

Test runner

Ready to run.

Testing in
TestOps/sec
for-loop
for (var index = 0, length = array.length; index < length; index++) {
  callback(array[index], index, array);
}
ready
Array#forEach
array.forEach(callback);
ready
for-loop naive
for (var index = 0; index < array.length; index++) {
  callback(array[index], index, array);
}
ready
for-loop reversed
for (var index = array.length; index--;) {
  callback(array[index], index, array);
}
ready

Revisions

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