Math's Min Max vs homemade

JavaScript performance comparison

Test case created by Ryan

Preparation code

function minMax(){
var min = 0;
var max = 0;
for(var i =1, len = arguments.length; i<len; i++){
if(arguments[max]<arguments[i])max = i;
if(arguments[min]>arguments[i])min = i;
}
return {max:arguments[max],min:arguments[min]};
}
var min;
var max;
var minmax;

    

Preparation code output

function minMax(){ var min = 0; var max = 0; for(var i =1, len = arguments.length; i<len; i++){ if(arguments[max]<arguments[i])max = i; if(arguments[min]>arguments[i])min = i; } return {max:arguments[max],min:arguments[min]}; } var min; var max; var minmax;

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 Lib
min = Math.min(0,3,2,-2,29,40,0,23);
max = Math.max(0,3,2,-2,29,40,0,23);
pending…
homemade
minmax = minMax(0,3,2,-2,29,40,0,23);
min = minmax.min;
max = minmax.max;
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

function minMax(){ var min = 0; var max = 0; for(var i =1, len = arguments.length; iarguments[i])min = i; } return {max:arguments[max],min:arguments[min]}; } var min; var max; var minmax;