Test name | Executions per second |
---|---|
roundScale | 3662420.5 Ops/sec |
roundPow | 3578144.8 Ops/sec |
bitRoundPow | 5620422.0 Ops/sec |
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; };
roundScale(Math.random() * 100, 1000)
roundPow(Math.random() * 100, 3)
bitRound(Math.random() * 100, 3)