LoDash, Underscore, and Native Reduce (v2)

Revision 2 of this benchmark created on


Description

A quick look at Lo-Dash 2.4.1, Underscore 1.7, and Native Performance on common functional operations.

This covers reduce, using the common case of getting the maximum value in a group of numbers

Preparation HTML

<script src="//cdnjs.cloudflare.com/ajax/libs/underscore.js/1.7.0/underscore.js"></script>
<script>
var underscore = _.noConflict();
</script>
<script src="//cdn.rawgit.com/lodash/lodash/9c6ef342708f009f04910111d692a124b2a961ae/dist/lodash.js"></script>
<script>
var lodash = _.noConflict();
</script>

Setup

var arr = [];
     var arr2 = [];
     for (var i = 0; i < 10000; i++) {
       arr.push({
         index: i,
         random: Math.random() * 10000
       });
    
     }

Test runner

Ready to run.

Testing in
TestOps/sec
Native Reduce
var max = arr.reduce(function(memo,iter){
   return memo >= iter.random ? memo : iter.random;
},0)
ready
Native For Loop Reduce
var max = 0, i=0, l=arr.length;

for(;i<l;i++) {
  max = max >= arr[i].random ? max : arr[i].random;
}
ready
Underscore Reduce
var max = underscore.reduce(arr, function(memo, iter){
   return memo >= iter.random ? memo : iter.random;
},0)
ready
Lo-Dash Reduce
var max = lodash.reduce(arr, function(memo, iter){
   return memo >= iter.random ? memo : iter.random;
},0)
ready
Arrow Reduce
var max = arr.reduce((memo, iter) => memo >= iter.random ? memo : iter.random
,0)
ready

Revisions

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

  • Revision 1: published by Ben McCormick on
  • Revision 2: published on