Run details:
Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36
Chrome 127
Linux
Desktop
one year ago
Math.floor fast
12.8M/s
toPrecision(4).toString()
5.1M/s
Math.trunc
4.4M/s
(Math.round(*10000)/10000).toString()
4.4M/s
toFixed(4) someFloat.toFixed(4); someFloat.t
4.1M/s
View exact numbers
Test name Executions per second
Math.floor fast 12,826,880 Ops/sec
toPrecision(4).toString() 5,135,608 Ops/sec
Math.trunc 4,394,796 Ops/sec
(Math.round(*10000)/10000).toString() 4,360,968 Ops/sec
toFixed(4) someFloat.toFixed(4); someFloat.t 4,119,286 Ops/sec
Script Preparation code:
Tests: