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

Revision 14 of this benchmark created on


Preparation HTML

<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/2.4.1/lodash.js"></script>
<script src="http://underscorejs.org/underscore.js"></script>

Setup

var lodash = _.noConflict();
    var ar = lodash.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; i < c; i++) {
  sum += ar[i]
}
ready
javascript reduce
ar.reduce(function(sum, el) {
  return sum + el
}, 0)
ready
lo-dash reduce
lodash.reduce(ar, 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.