Run details:
Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36
Chrome 123
Linux
Desktop
2 years ago
Math.floor fast
31.9M/s
toPrecision(4).toString()
13.8M/s
toFixed(4) someFloat.toFixed(4); someFloat.t
11.8M/s
Math.trunc
11.7M/s
(Math.round(*10000)/10000).toString()
11.7M/s
View exact numbers
Test name Executions per second
Math.floor fast 31,879,904 Ops/sec
toPrecision(4).toString() 13,751,834 Ops/sec
toFixed(4) someFloat.toFixed(4); someFloat.t 11,841,986 Ops/sec
Math.trunc 11,741,203 Ops/sec
(Math.round(*10000)/10000).toString() 11,652,377 Ops/sec
Script Preparation code:
Tests: