Run details:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36
Chrome 130
Mac OS X 10.15.7
Desktop
one year ago
Math.floor fast
72.9M/s
Math.trunc
62.2M/s
(Math.round(*10000)/10000).toString()
57.4M/s
toPrecision(4).toString()
8.6M/s
toFixed(4) someFloat.toFixed(4); someFloat.t
6.8M/s
View exact numbers
Test name Executions per second
Math.floor fast 72,854,160 Ops/sec
Math.trunc 62,228,132 Ops/sec
(Math.round(*10000)/10000).toString() 57,350,272 Ops/sec
toPrecision(4).toString() 8,578,144 Ops/sec
toFixed(4) someFloat.toFixed(4); someFloat.t 6,845,046 Ops/sec
Script Preparation code:
Tests: