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 assing first
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/120.0.0.0 Safari/537.36 Edg/120.0.0.0
Browser:
Chrome 120
Operating system:
Windows
Device Platform:
Desktop
Date tested:
2 years ago
ternary
518.1M/s
if
517.2M/s
assing first
515.7M/s
Math.min
3.7M/s
View exact numbers
Test name
Executions per second
✓
ternary
518,111,200 Ops/sec
if
517,160,704 Ops/sec
assing first
515,657,024 Ops/sec
Math.min
3,680,470 Ops/sec
Script Preparation code:
this.numberA = Math.random() * 1000; this.numberB = Math.random() * 1000;
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
assing first
var min = this.numberB; if (this.numberA < this.numberB) min = this.numberA; return min;