for each vs for loop (v117)

Revision 117 of this benchmark created by Yasser on


Description

Reverting to correct forEach and adding test cases to compare inline vs function calls

Setup

var arr = [];
    for (var i = 0; i < 100000; i++) arr[i] = i;
    var sum = 0;
    
    function addToSum(value) {
      value += sum;
    }

Test runner

Ready to run.

Testing in
TestOps/sec
for each inline
arr.forEach(function(value) {
  sum += value;
})
ready
for loop inline
for (var i = 0, l = arr.length; i < l; i++) {
  sum += arr[i];
}
ready
for each function
arr.forEach(addToSum)
ready
for loop function
for (var i = 0, l = arr.length; i < l; i++) {
  addToSum(arr[i]);
}
ready

Revisions

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