Run details:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36 OPR/73.0.3856.344
Opera 73
Mac OS X 10.15.7
Desktop
one year ago
Test name Executions per second
myFloat.toFixed(2) 686650.6 Ops/sec
myFloat.toPrecision(2) 916620.9 Ops/sec
Math.round(myFloat*100.0)/100.0 888427.9 Ops/sec
Bitwise: signed round ± to 2 places 1010021.7 Ops/sec
Bitwise: UNsigned round ± to 2 places 1385122.8 Ops/sec
myFloat.toFixed(0) 668558.1 Ops/sec
Math.round() 954068.8 Ops/sec
Bitwise: signed round ± to int 952099.2 Ops/sec
Bitwise: UNsigned round ± to int 1354401.0 Ops/sec
Math.floor() round down 856373.4 Ops/sec
Math.trunc() round toward zero 876845.7 Ops/sec
Bitwise: round toward zero 1442250.2 Ops/sec
Script Preparation code:
Tests:
  • myFloat.toFixed(2)

  • myFloat.toPrecision(2)

  • Math.round(myFloat*100.0)/100.0

  • Bitwise: signed round ± to 2 places

  • Bitwise: UNsigned round ± to 2 places

  • myFloat.toFixed(0)

  • Math.round()

  • Bitwise: signed round ± to int

  • Bitwise: UNsigned round ± to int

  • Math.floor() round down

  • Math.trunc() round toward zero

  • Bitwise: round toward zero


;