Run details:
Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36
Chrome 131
Linux
Desktop
one year ago
Math.floor fast
132.2M/s
Math.trunc
95.0M/s
(Math.round(*10000)/10000).toString()
94.1M/s
toPrecision(4).toString()
9.6M/s
toFixed(4) someFloat.toFixed(4); someFloat.t
8.2M/s
View exact numbers
Test name Executions per second
Math.floor fast 132,150,768 Ops/sec
Math.trunc 94,964,440 Ops/sec
(Math.round(*10000)/10000).toString() 94,146,128 Ops/sec
toPrecision(4).toString() 9,563,081 Ops/sec
toFixed(4) someFloat.toFixed(4); someFloat.t 8,243,412 Ops/sec
Script Preparation code:
Tests: