Test case details

Preparation Code

const NUMBERS = Array.from({length:1000000}, () => Math.random() * 32768) const BITSET = new Uint32Array(32768 / 32)

Test cases

Test #1

for (const bitidx of NUMBERS) { BITSET[~~(bitidx / 32)] ^= 1 << (bitidx % 32) }

Test #2

for (const bitidx of NUMBERS) { BITSET[0 | (bitidx / 32)] ^= 1 << (bitidx % 32) }

Test #3

for (const bitidx of NUMBERS) { BITSET[Math.floor(bitidx / 32)] ^= 1 << (bitidx % 32) }

Test #4

for (const bitidx of NUMBERS) { BITSET[Math.trunc(bitidx / 32)] ^= 1 << (bitidx % 32) }

Test #5

const floor = Math.floor // intuitively, this asserts to jit that `floor` will never be overwritten and is perfect for inlining for (const bitidx of NUMBERS) { BITSET[floor(bitidx / 32)] ^= 1 << (bitidx % 32) }

Test #6

const trunc = Math.trunc // intuitively, this asserts to jit that `trunc` will never be overwritten and is perfect for inlining for (const bitidx of NUMBERS) { BITSET[trunc(bitidx / 32)] ^= 1 << (bitidx % 32) }

Test #7

for (const bitidx of NUMBERS) { BITSET[bitidx >>> 5] ^= 1 << (bitidx % 32) }

Test #8

for (const bitidx of NUMBERS) { BITSET[bitidx >> 5] ^= 1 << (bitidx % 32) }

Test #9

for (const bitidx of NUMBERS) { BITSET[~~(bitidx / 32)] ^= 1 << (bitidx & 31) }

Test #10

for (const bitidx of NUMBERS) { BITSET[0 | (bitidx / 32)] ^= 1 << (bitidx & 31) }

Test #11

for (const bitidx of NUMBERS) { BITSET[Math.floor(bitidx / 32)] ^= 1 << (bitidx & 31) }

Test #12

for (const bitidx of NUMBERS) { BITSET[Math.trunc(bitidx / 32)] ^= 1 << (bitidx & 31) }

Test #13

const floor = Math.floor // intuitively, this asserts to jit that `floor` will never be overwritten and is perfect for inlining for (const bitidx of NUMBERS) { BITSET[floor(bitidx / 32)] ^= 1 << (bitidx & 31) }

Test #14

const trunc = Math.trunc // intuitively, this asserts to jit that `trunc` will never be overwritten and is perfect for inlining for (const bitidx of NUMBERS) { BITSET[trunc(bitidx / 32)] ^= 1 << (bitidx & 31) }

Test #15

for (const bitidx of NUMBERS) { BITSET[bitidx >>> 5] ^= 1 << (bitidx & 31) }

Test #16

for (const bitidx of NUMBERS) { BITSET[bitidx >> 5] ^= 1 << (bitidx & 31) }