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
14.0M/s
toPrecision(4).toString()
5.2M/s
Math.trunc
4.4M/s
(Math.round(*10000)/10000).toString()
4.4M/s
toFixed(4) someFloat.toFixed(4); someFloat.t
3.9M/s
View exact numbers
Test name Executions per second
Math.floor fast 13,971,735 Ops/sec
toPrecision(4).toString() 5,238,744 Ops/sec
Math.trunc 4,425,470 Ops/sec
(Math.round(*10000)/10000).toString() 4,412,660 Ops/sec
toFixed(4) someFloat.toFixed(4); someFloat.t 3,926,790 Ops/sec
Script Preparation code:
Tests: