Run details:
Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Safari/537.36
Chrome 117
Linux
Desktop
2 years ago
Math.floor fast
26.9M/s
Math.trunc
9.1M/s
toPrecision(4).toString()
8.5M/s
(Math.round(*10000)/10000).toString()
8.2M/s
toFixed(4) someFloat.toFixed(4); someFloat.t
7.7M/s
View exact numbers
Test name Executions per second
Math.floor fast 26,858,518 Ops/sec
Math.trunc 9,145,719 Ops/sec
toPrecision(4).toString() 8,504,418 Ops/sec
(Math.round(*10000)/10000).toString() 8,229,848 Ops/sec
toFixed(4) someFloat.toFixed(4); someFloat.t 7,654,460 Ops/sec
Script Preparation code:
Tests: