Run details:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/147.0.0.0 Safari/537.36
Chrome 147
Windows
Desktop
2 months ago
Math.floor fast
130.1M/s
(Math.round(*10000)/10000).toString()
127.3M/s
Math.trunc
121.9M/s
toPrecision(4).toString()
16.6M/s
toFixed(4) someFloat.toFixed(4); someFloat.t
11.0M/s
View exact numbers
Test name Executions per second
Math.floor fast 130,093,736 Ops/sec
(Math.round(*10000)/10000).toString() 127,316,816 Ops/sec
Math.trunc 121,926,080 Ops/sec
toPrecision(4).toString() 16,568,263 Ops/sec
toFixed(4) someFloat.toFixed(4); someFloat.t 10,964,273 Ops/sec
Script Preparation code:
Tests: