Run details:
Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36
Chrome 121
Linux
Desktop
2 years ago
Math.floor fast
24.7M/s
toPrecision(4).toString()
9.6M/s
(Math.round(*10000)/10000).toString()
9.5M/s
Math.trunc
9.4M/s
toFixed(4) someFloat.toFixed(4); someFloat.t
8.6M/s
View exact numbers
Test name Executions per second
Math.floor fast 24,694,262 Ops/sec
toPrecision(4).toString() 9,599,003 Ops/sec
(Math.round(*10000)/10000).toString() 9,532,204 Ops/sec
Math.trunc 9,374,881 Ops/sec
toFixed(4) someFloat.toFixed(4); someFloat.t 8,559,910 Ops/sec
Script Preparation code:
Tests: