Max value

JavaScript performance comparison

Test case created by Filip Smets

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    array = [1, 5, 64, 15, 2, 4, 689, 4, 48, 17, 14, 7, 97, 7, 745, 3, 1, 5, 50]
};
</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
loop
var largest = -Infinity;  
for (var i = 0; i < array.length; i++)  
{  
    if (array[i] > largest)  
    {  
        largest = array[i];
    }  
}  
pending…
max
Math.max.apply(Math, array)
pending…

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

Compare results of other browsers

0 comments

Add a comment