bitset mischief (v2)

Revision 2 of this benchmark created on


Description

why does wolf-ecs manipulate its bitsets like it do

Setup

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

Test runner

Ready to run.

Testing in
TestOps/sec
div, double-bitinv, modulo (as written in wolfecs)
for (const bitidx of NUMBERS) {
	BITSET[~~(bitidx / 32)] ^= 1 << (bitidx % 32)
}
ready
div, bitor-zero, modulo
for (const bitidx of NUMBERS) {
	BITSET[0 | (bitidx / 32)] ^= 1 << (bitidx % 32)
}
ready
div, Math.floor, modulo
for (const bitidx of NUMBERS) {
	BITSET[Math.floor(bitidx / 32)] ^= 1 << (bitidx % 32)
}
ready
div, Math.trunc, modulo
for (const bitidx of NUMBERS) {
	BITSET[Math.trunc(bitidx / 32)] ^= 1 << (bitidx % 32)
}
ready
div, local floor, modulo
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)
}
ready
div, local trunc, modulo
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)
}
ready
unsigned shr, modulo
for (const bitidx of NUMBERS) {
	BITSET[bitidx >>> 5] ^= 1 << (bitidx % 32)
}
ready
signed shr, modulo
for (const bitidx of NUMBERS) {
	BITSET[bitidx >> 5] ^= 1 << (bitidx % 32)
}
ready
div, double-bitinv, bitand
for (const bitidx of NUMBERS) {
	BITSET[~~(bitidx / 32)] ^= 1 << (bitidx & 31)
}
ready
div, bitor-zero, bitand
for (const bitidx of NUMBERS) {
	BITSET[0 | (bitidx / 32)] ^= 1 << (bitidx & 31)
}
ready
div, Math.floor, bitand
for (const bitidx of NUMBERS) {
	BITSET[Math.floor(bitidx / 32)] ^= 1 << (bitidx & 31)
}
ready
div, Math.trunc, bitand
for (const bitidx of NUMBERS) {
	BITSET[Math.trunc(bitidx / 32)] ^= 1 << (bitidx & 31)
}
ready
div, local floor, bitand
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)
}
ready
div, local trunc, bitand
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)
}
ready
unsigned shr, bitand
for (const bitidx of NUMBERS) {
	BITSET[bitidx >>> 5] ^= 1 << (bitidx & 31)
}
ready
signed shr, bitand
for (const bitidx of NUMBERS) {
	BITSET[bitidx >> 5] ^= 1 << (bitidx & 31)
}
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.