Skip to content

Conversation

@liamdon
Copy link

@liamdon liamdon commented Dec 3, 2023

The lookup table approach is really neat, but after running some benchmarks it looks like we can get a ~10-15x speedup by using the built-in Math.clz32()

Benchmark

let n = 2;
for (let i = 0; i < 16; i++) {
	getLSBIndex(n);
	n *= 2;
}

Chrome 119

Approach Second Header
Math.clz32 145M ops/s ± 0.48%
Lookup table 9.8M ops/s ± 0.24% (93.21% slower)

Safari 17.9

Approach Second Header
Math.clz32 120M ops/s ± 0.24%
Lookup table 12M ops/s ± 0.51%. (89.76% slower)

Math.clz32() Browser support

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant