Array reduce vs forEach (v7)

Revision 7 of this benchmark created on


Setup

var array = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

Teardown


    console.log(total);
  

Test runner

Ready to run.

Testing in
TestOps/sec
forEach
var array = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
var total = 0;
array.forEach(function(val) {
  total += val;
});
ready
reduce
var array = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
var total = array.reduce(function(prev, curr) {
  return prev + curr;
});
ready

Revisions

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