Run details:
Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36
Chrome 124
Linux
Desktop
2 years ago
Math.floor fast
10.0M/s
Math.trunc
3.4M/s
(Math.round(*10000)/10000).toString()
3.4M/s
toPrecision(4).toString()
3.3M/s
toFixed(4) someFloat.toFixed(4); someFloat.t
2.4M/s
View exact numbers
Test name Executions per second
Math.floor fast 10,005,166 Ops/sec
Math.trunc 3,406,527 Ops/sec
(Math.round(*10000)/10000).toString() 3,404,416 Ops/sec
toPrecision(4).toString() 3,259,979 Ops/sec
toFixed(4) someFloat.toFixed(4); someFloat.t 2,445,480 Ops/sec
Script Preparation code:
Tests: