for vs array-foreach (v4)

Revision 4 of this benchmark created by John-David Dalton on


Setup

var array = Array(31).join('x').split('');
    
    function callback(value, index, object) {
      return value + index;
    }
    
    function customForEach(array, callback, thisArg) {
      var fn = callback,
          index = -1,
          length = array.length;
    
      while (++index < length) {
        if (callback(array[index], index, array) === false) {
          break;
        }
      }
      return array;
    }

Test runner

Ready to run.

Testing in
TestOps/sec
custom forEach
customForEach(array, callback);
ready
Array#forEach
array.forEach(callback);
ready

Revisions

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