Run details:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36
Chrome 131
Mac OS X 10.15.7
Desktop
one year ago
Math.floor fast
152.2M/s
Math.trunc
126.4M/s
(Math.round(*10000)/10000).toString()
125.2M/s
toPrecision(4).toString()
12.8M/s
toFixed(4) someFloat.toFixed(4); someFloat.t
9.1M/s
View exact numbers
Test name Executions per second
Math.floor fast 152,236,384 Ops/sec
Math.trunc 126,389,728 Ops/sec
(Math.round(*10000)/10000).toString() 125,239,688 Ops/sec
toPrecision(4).toString() 12,810,185 Ops/sec
toFixed(4) someFloat.toFixed(4); someFloat.t 9,137,917 Ops/sec
Script Preparation code:
Tests: