Array reduce vs forEach (v19)

Revision 19 of this benchmark created on


Setup

var array = []
    for (var i = 0; i < 100000; i++) {
        array.push(Math.random());
    }

Teardown


    console.log(total);
  

Test runner

Ready to run.

Testing in
TestOps/sec
for
var total = 0;
for (var i = 0; i < array.length; i++) {
    total += array[i];
}
 
ready
for with l
var total = 0;
for (var i = 0, l = array.length; i < l; i++) {
    total += array[i];
}
 
ready
while
var total = 0,
    i = array.length;
while (i--) {
    total += array[i];
}
 
ready

Revisions

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