Math vs Ternary
Date tested:
one year ago
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.0.0 Safari/537.36
Test name
Executions per second
Math
6709784.0 Ops/sec
Ternary
1013698000.0 Ops/sec
Benchmark definition (click to collapse):
Script Preparation code:
const n = Math.random() * 1000;
Tests:
Math
return Math.max(250, Math.min(750, this.n));
Ternary
return this.n < 250 ? 250 : this.n > 750 ? 750 : this.n;
Open this result on MeasureThat.net