Fast Array Foreach (v369)

Revision 369 of this benchmark created by Sascha Tandel on


Setup

// Populate the base array
    var arr = [];
    for (var i = 0; i < 1000; i++) {
      arr[i] = i;
    }
  
    function someFn(i) {
      return i * 3 * 8;
    }
  
  function forEach (arr, iterate) {
    var length = arr.length
    var index = -1
    while (++index < length) {
      iterate(arr[index], index)
    }
  }

Test runner

Ready to run.

Testing in
TestOps/sec
while
var length = arr.length
var index = -1
while (++index < length) {
  someFn(arr[index])
}
ready
forEach
forEach(arr, someFn)
ready

Revisions

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