Run details:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Safari/537.36
Chrome 117
Mac OS X 10.15.7
Desktop
one year ago
Test name Executions per second
myFloat.toFixed(2) 1412317.6 Ops/sec
myFloat.toPrecision(2) 1349155.6 Ops/sec
Math.round(myFloat*100.0)/100.0 1317310.9 Ops/sec
Bitwise: signed round ± to 2 places 1366021.2 Ops/sec
Bitwise: UNsigned round ± to 2 places 1967181.6 Ops/sec
myFloat.toFixed(0) 1396065.2 Ops/sec
Math.round() 1422105.1 Ops/sec
Bitwise: signed round ± to int 2094295.2 Ops/sec
Bitwise: UNsigned round ± to int 3073216.5 Ops/sec
Math.floor() round down 1716588.8 Ops/sec
Math.trunc() round toward zero 1742731.1 Ops/sec
Bitwise: round toward zero 3115446.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