for vs array-foreach (v23)

Revision 23 of this benchmark created on


Setup

var array = new Uint8Array(1000);
    for(var i = 0, l = array.length; i < l; i++){
      array[i] = 10;
    }
    
    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-in
for (var index in array) {
  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.