Run details:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.84 Safari/537.36
Chrome 99
Windows
Desktop
one year ago
Math.floor fast
641.7M/s
Math.trunc
203.0M/s
(Math.round(*10000)/10000).toString()
188.2M/s
toPrecision(4).toString()
6.2M/s
toFixed(4) someFloat.toFixed(4); someFloat.t
6.0M/s
View exact numbers
Test name Executions per second
Math.floor fast 641,678,336 Ops/sec
Math.trunc 202,984,560 Ops/sec
(Math.round(*10000)/10000).toString() 188,229,280 Ops/sec
toPrecision(4).toString() 6,205,864 Ops/sec
toFixed(4) someFloat.toFixed(4); someFloat.t 6,013,516 Ops/sec
Script Preparation code:
Tests: