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 (X11; Linux x86_64; rv:151.0) Gecko/20100101 Firefox/151.0
Browser:
Firefox 151
Operating system:
Linux
Device Platform:
Desktop
Date tested:
one month ago
assing first
2989.4M/s
ternary
2987.8M/s
if
2985.7M/s
Math.min
100.3M/s
View exact numbers
Test name
Executions per second
✓
assing first
2,989,363,456 Ops/sec
ternary
2,987,791,872 Ops/sec
if
2,985,676,288 Ops/sec
Math.min
100,274,040 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;