modulo vs bitwise (v2)

Revision 2 of this benchmark created on


Setup

const numbers = new Array(1_000_000).fill(true).map(() => {
	return Math.floor(Math.random()*1_000_000)
});


Test runner

Ready to run.

Testing in
TestOps/sec
modulo
let count = 0; 
numbers.forEach((v) => {
	if (v % 2 === 0){
		count++;
	}
})
ready
bitwise xor
let count = 0; 
numbers.forEach((v) => {
	if ((v^1) === v+1){
		count++;
	}
})
ready
bitwise add
let count = 0; 
numbers.forEach((v) => {
	if ((v&1) === 0){
		count++;
	}
})
ready

Revisions

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