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 |
function getRandomUint32(min, max) {
return Math.floor(Math.random() * (max - min) + min);
}
for(let i = 0; i < 100; i++) {
const z = getRandomUint32(0, 2 ** 32) < 2_147_483_648;
}
for(let i = 0; i < 100; i++) {
const z = getRandomUint32(0, 2 ** 32) % 2 === 0;
}
for(let i = 0; i < 100; i++) {
const z = getRandomUint32(0, 2 ** 32) & 1 === 1;
}