Надо ли выносить массив в константу

Benchmark created on


Test runner

Ready to run.

Testing in
TestOps/sec
includes
let s = 0;
for (let i = 0; i < 1000; i++) {
	const n = i % 11;
	if ([2, 3, 5, 7, 9].includes(n)) {
		s += 1;
	}
}
ready
if
let s = 0;
for (let i = 0; i < 1000; i++) {
	const n = i % 11;
	if (n === 2 || n === 3 || n === 5 || n === 7 || n === 9) {
		s += 1;
	}
}
ready
pre-saved
let s = 0;
const ARRAY = [2, 3, 5, 7, 9];
for (let i = 0; i < 1000; i++) {
	const n = i % 11;
	if (ARRAY.includes(n)) {
		s += 1;
	}
}
ready

Revisions

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