Maximum value in array tests

JavaScript performance comparison

Test case created

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    a = []
   
    for (i = 0; i < 5000; i++) {
        a[i] = Math.round(Math.random() * 100000);
    }
   
    function array_max_1(a) {
        var max = null;
        for (i = a.length - 1; i > -1; i--) {
            if (a[i] > max || typeof max === 'null') {
                max = a[i];
            }
        }
        return max;
    }
   
    function array_max_2(a) {
        var max = null;
        for (i = a.length - 1; i >= 0; i--) {
            if (a[i] > max || typeof max === 'null') {
                max = a[i];
            }
        }
        return max;
    }
};
</script>

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
array_max_1()
array_max_1(a);
pending…
array_max_2()
array_max_2(a);
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. Here’s a list of current revisions for this page:

0 comments

Add a comment