Summing array elements: underscore reduce vs javascript reduce vs for (v3)

Revision 3 of this benchmark created on


Preparation HTML

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

Setup

var ar = _.range(10000)
    var c = ar.length
    var sum = 0

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, l = c.length; i < l; i++) {
  sum += ar[i]
}
ready
javascript 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.