indexOfMax-130,000

JavaScript performance comparison

Test case created by zawaliang

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  var arr = [];
  for (var i = 0; i < 130000; i++) {
      arr[i] = i;
  }

};
</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
for
var maxIndex = 0;
for (var i = 1, len = arr.length; i < len; i++) {
    if (arr[i] > arr[maxIndex]) {
        maxIndex = i;
    }
}
pending…
reduce
arr.reduce(function(max, next, index) {
    return next > arr[max] ? index : max;
}, 0);
pending…
indexOf/max
arr.indexOf(Math.max.apply(Math, arr));
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