Run details:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36
Chrome 114
Mac OS X 10.15.7
Desktop
one year ago
Test name Executions per second
roundScale 3662420.5 Ops/sec
roundPow 3578144.8 Ops/sec
bitRoundPow 5620422.0 Ops/sec
Script Preparation code:
AخA
 
window.roundScale = (val, scale) => { return Math.round(val * scale) / scale; };
window.roundPow = (val, precision) => { const m = 10 ** (precision || 0); return Math.round(val * m) / m; };
window.bitRound = (val, precision) => { const m = 10 ** (precision || 0); return ((((val * m) + 0.5) << 1) >> 1) / m; };
Tests:
  • roundScale

     
    roundScale(Math.random() * 100, 1000)
  • roundPow

     
    roundPow(Math.random() * 100, 3)
  • bitRoundPow

     
    bitRound(Math.random() * 100, 3)