Fast Array Foreach (v246)

Revision 246 of this benchmark created by WSChang on


Setup

// Populate the base array
      var arr = [];
      for (var i = 0; i < 1000; i++) {
        arr[i] = i;
      }
    
      var arrResult = [];

Test runner

Ready to run.

Testing in
TestOps/sec
Array.ForEach
arr.forEach(function(item, index) {
  arrResult[index] = item + 1;
})
ready
For
for (var i = 0, len = arr.length; i < len; i++) {
  arrResult[i] = arr[i] + 1
}
ready
Array.ForEach (dummy)
arr.forEach(function() {
})
ready
For (dummy)
for (var i = 0, len = arr.length; i < len; i++) {
}
ready
For (Decrement)
for (var i = arr.length-1; i > -1; --i) {
  arrResult[i] = arr[i] + 1
}
ready

Revisions

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