Math.min & Math.max

Benchmark created by Etienne Lemay on


Setup

min = 0
    max = 100

Test runner

Ready to run.

Testing in
TestOps/sec
Math.min | Math.max
value = 5
value = Math.max(min, value)
value = Math.min(max, value)
console.log(value)

value = 200
value = Math.max(min, value)
value = Math.min(max, value)
console.log(value)
 
ready
If | Else
value = 5
if (value < min) { value = min }
if (value > max) { value = max }
console.log(value)

value = 200
if (value < min) { value = min }
if (value > max) { value = max }
console.log(value)
 
ready

Revisions

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

  • Revision 1: published by Etienne Lemay on