a

Benchmark created on


Setup

const nums = [34,513,513434, 13453145, 134555, 133, 44113, 5, 1,34,23,54326,462,436452,64526,2456,2456,2456,2465,2456,3425,234,2341,324,534,5435,234,34324,123213,123,123,123,4324,234,234,234];
const bits = 30;
	

		const bitsLessThan32 = 32 - bits;
		const mask = 0xFF_FF_FF_FF >>> bitsLessThan32;
		const maskn = 0xFF_FF_FF_FFn >> BigInt(bitsLessThan32);
		const a = integer => Math.clz32(
			typeof integer === "number" ? (integer & mask) :
			Number(BigInt.asUintN(bits, integer))
		) - bitsLessThan32;
	
		const b = integer => Math.clz32(
			typeof integer === "number" ? (integer & mask) :
			Number(integer & maskn)
		) - bitsLessThan32;

Test runner

Ready to run.

Testing in
TestOps/sec
a
let p = 0;
for(let i = 0; i !== 9999; ++i)
for(const y of nums) {
	p += a(y);
}
re =p
ready
b
let q = 0;
for(let i = 0; i !== 9999; ++i)
for(const y of nums) {
	q += b(y);
}
re=q
ready

Revisions

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