Run details:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36
Chrome 123
Windows
Desktop
2 years ago
Math.floor fast
7.0M/s
(Math.round(*10000)/10000).toString()
2.9M/s
toPrecision(4).toString()
2.7M/s
Math.trunc
2.5M/s
toFixed(4) someFloat.toFixed(4); someFloat.t
2.5M/s
View exact numbers
Test name Executions per second
Math.floor fast 7,031,964 Ops/sec
(Math.round(*10000)/10000).toString() 2,922,721 Ops/sec
toPrecision(4).toString() 2,727,913 Ops/sec
Math.trunc 2,507,894 Ops/sec
toFixed(4) someFloat.toFixed(4); someFloat.t 2,479,671 Ops/sec
Script Preparation code:
Tests: