Run details:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Safari/537.36 Edg/134.0.0.0
Chrome 134
Windows
Desktop
one year ago
Math.floor fast
153.8M/s
(Math.round(*10000)/10000).toString()
148.0M/s
Math.trunc
147.6M/s
toPrecision(4).toString()
19.8M/s
toFixed(4) someFloat.toFixed(4); someFloat.t
14.9M/s
View exact numbers
Test name Executions per second
Math.floor fast 153,823,888 Ops/sec
(Math.round(*10000)/10000).toString() 148,027,504 Ops/sec
Math.trunc 147,641,472 Ops/sec
toPrecision(4).toString() 19,771,620 Ops/sec
toFixed(4) someFloat.toFixed(4); someFloat.t 14,902,346 Ops/sec
Script Preparation code:
Tests: