Calculate Max: Math.max.apply vs Array.reduce

JavaScript performance comparison

Test case created by

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  var array = [],
      times = 10000;
    
  for (var i = 0; i < times; i++) {
      array.push({value:Math.round(Math.random() * times)})
  }

};
</script>

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
Math.max.apply
Math.max.apply(Math, array.map(function (n) { return n.value; }));
pending…
Array.reduce
array.map(function(n){ return n.value;}).reduce(function(pre, cur){ return Math.max(pre, cur);});
pending…

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

0 Comments