Modulus vs div+mul

Benchmark created on


Setup

const bits = Object.keys(Array(256).join('x').split('x'));

Test runner

Ready to run.

Testing in
TestOps/sec
Modulus
for (const b of bits) {
	const byte = Math.floor(b / 8);
	const bit = b % 8;
}
ready
Div & mul
for (const b of bits) {
	const byte = Math.floor(b / 8);
	const bit = b  - byte * 8;
}
ready
Shifts
for (const b of bits) {
	const byte = b >> 3;
	const bit = b  - (byte << 3);
}
ready

Revisions

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