Run details:
Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 Safari/537.36
Chrome 118
Linux
Desktop
2 years ago
Math.floor fast
18.3M/s
(Math.round(*10000)/10000).toString()
5.5M/s
Math.trunc
5.5M/s
toPrecision(4).toString()
5.4M/s
toFixed(4) someFloat.toFixed(4); someFloat.t
4.4M/s
View exact numbers
Test name Executions per second
Math.floor fast 18,261,786 Ops/sec
(Math.round(*10000)/10000).toString() 5,530,938 Ops/sec
Math.trunc 5,486,382 Ops/sec
toPrecision(4).toString() 5,449,140 Ops/sec
toFixed(4) someFloat.toFixed(4); someFloat.t 4,406,922 Ops/sec
Script Preparation code:
Tests: