map + every vs for of vs Set + every (v2)

Revision 2 of this benchmark created on


Description

Given a big list of elements. Check which one is faster to detect all items satisfy a condition

Setup

const array = new Array(1000).fill({
	property: 'test'
})

function check(topic) {
	return topic === 'test';
}

Test runner

Ready to run.

Testing in
TestOps/sec
map + every
const properties = array.map(item => item.property);
const result = properties.every(p => check(p));

console.log(result);
ready
for of
let result = true;
for (const item of array) {
	if (!check(item.property)) {
		result = false;
		break;
	}
}
console.log(result);
ready
set + every
let result = true;
const properties = new Set(array.map(item => item.property));

for (const property of properties) {
	if (!check(property)) {
		result = false;
		break;
	}
}

console.log(result);
ready

Revisions

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