Summing array elements: underscore reduce vs for (v8)

Revision 8 of this benchmark created by Eric Guthmann on


Description

Testing

Preparation HTML

<script src="http://underscorejs.org/underscore.js"></script>

Setup

var ar = _.range(10000)
    var sum = 0
    var amount, _i, _len;

Test runner

Ready to run.

Testing in
TestOps/sec
underscore reduce
_.reduce(ar, function(sum, el) {
  return sum + el
}, 0)
ready
for loop
for (var i = 0; i < ar.length; i++) {
  sum += ar[i]
}
ready
JS generated by coffeescript: sum += amount for amount in ar
for (_i = 0, _len = ar.length; _i < _len; _i++) {
  amount = ar[_i];
  sum += amount;
}
 
ready
Array reduce
ar.reduce(function(sum, el) {
  return sum + el
}, 0)
ready

Revisions

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