Fast Array Foreach (v243)

Revision 243 of this benchmark created by BinRui Guan 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

Revisions

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