Toggle navigation
MeasureThat
.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
Math.min vs if/else vs ternary operator vs logical or
Quickest operation to return smaller of 2 numbers
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36
Browser:
Chrome 133
Operating system:
Windows
Device Platform:
Desktop
Date tested:
one year ago
Math.min
24.8M/s
logical or
21.4M/s
if
14.7M/s
ternary
14.7M/s
View exact numbers
Test name
Executions per second
✓
Math.min
24,825,534 Ops/sec
logical or
21,442,940 Ops/sec
if
14,729,632 Ops/sec
ternary
14,707,881 Ops/sec
Script Preparation code:
this.numberA = Math.random() > .5 || 0; this.numberB = !this.numberA;
Tests:
Math.min
return Math.min(this.numberA, this.numberB);
if
if (this.numberA < this.numberB) return this.numberA; else return this.numberB;
ternary
return (this.numberA < this.numberB) ? this.numberA : this.numberB
logical or
return this.numberA || this.numberB