Run details:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/135.0.0.0 Safari/537.36
Chrome 135
Windows
Desktop
one year ago
Math.trunc
119.4M/s
Math.floor fast
118.7M/s
(Math.round(*10000)/10000).toString()
103.8M/s
toPrecision(4).toString()
9.8M/s
toFixed(4) someFloat.toFixed(4); someFloat.t
8.0M/s
View exact numbers
Test name Executions per second
Math.trunc 119,417,696 Ops/sec
Math.floor fast 118,711,320 Ops/sec
(Math.round(*10000)/10000).toString() 103,814,168 Ops/sec
toPrecision(4).toString() 9,791,924 Ops/sec
toFixed(4) someFloat.toFixed(4); someFloat.t 8,010,384 Ops/sec
Script Preparation code:
Tests: