Run details:
Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Mobile Safari/537.36
Chrome Mobile 117
Android
Mobile
one year ago
Test name Executions per second
myFloat.toFixed(2) 976976.4 Ops/sec
myFloat.toPrecision(2) 1106340.1 Ops/sec
Math.round(myFloat*100.0)/100.0 939800.3 Ops/sec
Bitwise: signed round ± to 2 places 1197993.5 Ops/sec
Bitwise: UNsigned round ± to 2 places 1665880.1 Ops/sec
myFloat.toFixed(0) 1019422.8 Ops/sec
Math.round() 1025757.7 Ops/sec
Bitwise: signed round ± to int 1320582.8 Ops/sec
Bitwise: UNsigned round ± to int 1879278.6 Ops/sec
Math.floor() round down 1026371.3 Ops/sec
Math.trunc() round toward zero 1025808.0 Ops/sec
Bitwise: round toward zero 1884406.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


;