Run details:
Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:128.0) Gecko/20100101 Firefox/128.0
Firefox 128
Windows
Desktop
9 months ago
Test name Executions per second
Compare to half of max int 21006774.0 Ops/sec
Mod even/odd 20871864.0 Ops/sec
Bitwise even/odd 20994424.0 Ops/sec
Script Preparation code:
AخA
 
function getRandomUint32(min, max) {
    return Math.floor(Math.random() * (max - min) + min);
}
Tests:
  • Compare to half of max int

     
    for(let i = 0; i < 100; i++) {
        const z = getRandomUint32(0, 2 ** 32) < 2_147_483_648;
    }
  • Mod even/odd

     
    for(let i = 0; i < 100; i++) {
        const z = getRandomUint32(0, 2 ** 32) % 2 === 0;
    }
  • Bitwise even/odd

     
    for(let i = 0; i < 100; i++) {
        const z = getRandomUint32(0, 2 ** 32) & 1 === 1;
    }