Run details:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36
Chrome 120
Windows
Desktop
2 years ago
Math.floor fast
10.4M/s
Math.trunc
3.9M/s
(Math.round(*10000)/10000).toString()
3.7M/s
toPrecision(4).toString()
3.3M/s
toFixed(4) someFloat.toFixed(4); someFloat.t
2.9M/s
View exact numbers
Test name Executions per second
Math.floor fast 10,404,697 Ops/sec
Math.trunc 3,855,734 Ops/sec
(Math.round(*10000)/10000).toString() 3,710,087 Ops/sec
toPrecision(4).toString() 3,262,269 Ops/sec
toFixed(4) someFloat.toFixed(4); someFloat.t 2,904,920 Ops/sec
Script Preparation code:
Tests: