Run details:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:109.0) Gecko/20100101 Firefox/109.0
Firefox 109
Mac OS X 10.15
Desktop
one year ago
Test name Executions per second
myFloat.toFixed(2) 3975132.2 Ops/sec
myFloat.toPrecision(2) 3440480.5 Ops/sec
Math.round(myFloat*100.0)/100.0 387574752.0 Ops/sec
Bitwise: signed round ± to 2 places 3069093.2 Ops/sec
Bitwise: UNsigned round ± to 2 places 392308704.0 Ops/sec
myFloat.toFixed(0) 3405053.2 Ops/sec
Math.round() 173029664.0 Ops/sec
Bitwise: signed round ± to int 8205285.5 Ops/sec
Bitwise: UNsigned round ± to int 174674032.0 Ops/sec
Math.floor() round down 173466768.0 Ops/sec
Math.trunc() round toward zero 169126608.0 Ops/sec
Bitwise: round toward zero 175198432.0 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