Run details:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36
Chrome 133
Mac OS X 10.15.7
Desktop
one year ago
Math.floor fast
182.6M/s
Math.trunc
176.5M/s
(Math.round(*10000)/10000).toString()
170.4M/s
toPrecision(4).toString()
31.9M/s
toFixed(4) someFloat.toFixed(4); someFloat.t
19.3M/s
View exact numbers
Test name Executions per second
Math.floor fast 182,606,352 Ops/sec
Math.trunc 176,509,504 Ops/sec
(Math.round(*10000)/10000).toString() 170,359,776 Ops/sec
toPrecision(4).toString() 31,942,058 Ops/sec
toFixed(4) someFloat.toFixed(4); someFloat.t 19,306,932 Ops/sec
Script Preparation code:
Tests: