Max Integer from array

JavaScript performance comparison

Test case created by Jack

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  asc = [];
  desc = [];
  rnd = [];
  
  for (var i = 0, n = 100000; i != n; ++i) {
      asc.push(i);
      desc.push(n - i);
      rnd.push(Math.floor(Math.random() * 5000 - 2500));
  }
  
  function mymax(a)
  {
      var m = -Infinity, i = 0, n = a.length;
  
      for (; i != n; ++i) {
          if (a[i] > m) {
              m = a[i];
          }
      }
  
      return m;
  }

};
</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
Using max.apply
var i;

i = Math.max.apply(Math, asc);
i = Math.max.apply(Math, desc);
i = Math.max.apply(Math, rnd);
pending…
Using mymax
var i;

i = mymax(asc);
i = mymax(desc);
i = mymax(rnd);
pending…

Compare results of other browsers

Revisions

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

0 Comments