Script Preparation code:
x
 
this.number = Math.random() * 1000;
function max(v1, v2) {
  if (v1 > v2) return v1;
  return v2;
}
function min(v1, v2) {
  if (v1 < v2) return v1;
  return v2;
}
Tests:
  • Math.max/min

     
    return Math.max(250, Math.min(750, this.number));
  • if

     
    var number = this.number;
    if(number < 250) return 250;
    if(number > 750) return 750;
    return number;
  • ternary

     
    var number = this.number;
    return number < 250 ? 250 : (number > 750 ? 750 : number);
  • custom function

     
    return max(250, min(750, this.number));
Rendered benchmark preparation results:

Suite status: <idle, ready to run>

Previous results

Experimental features:

  • Test case name Result
    Math.max/min
    if
    ternary
    custom function

    Fastest: N/A

    Slowest: N/A

Latest run results:
Run details: (Test run date: 2 years ago)
Mozilla/5.0 (X11; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/110.0
Firefox 110 on Linux
View result in a separate tab
Test name Executions per second
Math.max/min 17512906.0 Ops/sec
if 673137664.0 Ops/sec
ternary 672500736.0 Ops/sec
custom function 637094016.0 Ops/sec