Math vs underscore vs lodash vs d3 on large array (max) (v7)

Revision 7 of this benchmark created on


Preparation HTML

<script src="//underscorejs.org/underscore-min.js"></script>

<script src="//d3js.org/d3.v3.min.js" charset="utf-8"></script>

<script src="https://raw.github.com/lodash/lodash/2.4.1/dist/lodash.min.js"></script>

<script>
var lodash = _.noConflict();
</script>

Setup

var _ = window._;
    var d3 = window.d3;
    var lodash = window.lodash;
    var $Math = window.$Math;
    var Math = window.Math;
    d3.__max = function( array , f ) {
        var i = 0,
            n = array.length,
            a,
            b;
    
        if ( f ) {
            a = f.call( array , array[ i ] , i );
    
            while (++i < n) if ((b = f.call( array , array[ i ] , i )) != null && a < b) a = b;
        } else {
            a =                 array[ i ];
    
            while (++i < n) if ((b =                 array[i]        ) != null && a < b) a = b;
        }
    
        return a;
    };
    
    var arr = [], maxLimit = 1000000000;
    for (var i = 0; i < 100000; i++) {
      arr.push(Math.floor(Math.random() * maxLimit));
    }

Test runner

Ready to run.

Testing in
TestOps/sec
Math.max
Math.max.apply(null, arr);
ready
Underscore.max
_.max(arr);
ready
D3.max
d3.max(arr);
ready
Lo-Dash.max
lodash.max(arr);
ready
D3.__max
d3.__max(arr);
ready

Revisions

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