Check if odd or even

Benchmark created on


Setup

const list = [
0,1,2,3,4,5,6,7,8,9,10,11,
111,112,113,114,115,116,117,118,119,120,
100000000001,100000000002,100000000003,100000000004,100000000005,100000000006,100000000007,100000000008,100000000009,100000000010,
Number.MAX_SAFE_INTEGER, Number.MAX_SAFE_INTEGER - 1, Number.MAX_SAFE_INTEGER - 2, Number.MAX_SAFE_INTEGER - 3, Number.MAX_SAFE_INTEGER - 4
];

Test runner

Ready to run.

Testing in
TestOps/sec
Modulo
list.forEach((n) => {
	(n % 2) === 0
});
ready
Bitwise
list.forEach((n) => {
	(n & 1) === 0;
});
ready
Division Operator (/) and parseInt
list.forEach((n) => {
	parseInt(n / 2) === n / 2;
});
ready
Bit Shifting
list.forEach((n) => {
	 (n >> 1) << 1 === n;
});
ready
Math.floor
list.forEach((n) => {
	 Math.floor(n / 2) === n / 2;
});
ready
Array Lookup
const parity = ['even', 'odd'];
list.forEach((n) => {
	 parity[n % 2] === 'even';
});
ready
Ternary Operator
list.forEach((n) => {
	 n % 2 === 0 ? 'even' : 'odd';
});
ready

Revisions

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