bitset mischief

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
as written in wolfecs
for (const bitidx of NUMBERS) {
	BITSET[~~(bitidx / 32)] ^= 1 << (bitidx % 32)
}
ready
cast to int using bitor-zero
for (const bitidx of NUMBERS) {
	BITSET[0 | (bitidx / 32)] ^= 1 << (bitidx % 32)
}
ready
bitshift and 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.