Run details:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36
Chrome 124
Windows
Desktop
2 years ago
Math.floor fast
16.7M/s
(Math.round(*10000)/10000).toString()
6.4M/s
Math.trunc
6.4M/s
toPrecision(4).toString()
5.6M/s
toFixed(4) someFloat.toFixed(4); someFloat.t
4.6M/s
View exact numbers
Test name Executions per second
Math.floor fast 16,671,231 Ops/sec
(Math.round(*10000)/10000).toString() 6,444,566 Ops/sec
Math.trunc 6,369,672 Ops/sec
toPrecision(4).toString() 5,639,547 Ops/sec
toFixed(4) someFloat.toFixed(4); someFloat.t 4,558,706 Ops/sec
Script Preparation code:
Tests: