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

Revision 13 of this benchmark created on


Preparation HTML

<script src="https://lodash.com/_js/lodash.compat.js"></script>
<script src="http://underscorejs.org/underscore.js"></script>

Setup

if (_.VERSION){
        var lodash = _.noConflict();
    }
    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; i < c; 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.