Min and max in array

Benchmark created by Linus Unnebäck on


Setup

var values = [41,73,98,62,85,51,28,89,20];
    
    var minReduce = function (arr) {
      return arr.reduce(function (p, v) {
        return ( p < v ? p : v );
      });
    };
    var maxReduce = function (arr) {
      return arr.reduce(function (p, v) {
        return ( p > v ? p : v );
      });
    };
    
    var minMath = function (arr) {
        return Math.min.apply(Math, arr);
    };
    var maxMath = function (arr) {
        return Math.max.apply(Math, arr);
    };

Test runner

Ready to run.

Testing in
TestOps/sec
Reduce
maxReduce(values);
minReduce(values);
ready
Math
maxMath(values);
minMath(values);
ready

Revisions

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