Test name | Executions per second |
---|---|
myFloat.toFixed(2) | 1161921.4 Ops/sec |
myFloat.toPrecision(2) | 1139002.1 Ops/sec |
Math.round(myFloat*100)/100 i.e. 2 places | 982526.5 Ops/sec |
Bitwise: signed round to 2 places | 1310309.6 Ops/sec |
Bitwise: UNsigned round to 2 places | 1808399.6 Ops/sec |
myFloat.toFixed(0) i.e. round to int | 1202684.5 Ops/sec |
Math.round(myFloat) | 980657.2 Ops/sec |
Bitwise: signed round to nearest int | 1869211.5 Ops/sec |
Floor (round down only to int) | 959809.8 Ops/sec |
Trunc (round towards zero) | 973879.2 Ops/sec |
Bitwise: signed round to zero (trunc) | 1919674.9 Ops/sec |