looking for company (v2)

Revision 2 of this benchmark created on


Setup

// creating 100 people with 100 accounts inside
const people = Array.from({length: 100}, () => ({accounts: Array.from({length: 100}, () => ({id: Math.floor(Math.random() * 1000000)}))}));

// guaranteed to not exist in all arrays, which will force us to fully iterate all of them
const accountId = -1;

// and this one exists
const accountId2 = people[50].accounts[50].id;

Test runner

Ready to run.

Testing in
TestOps/sec
find company
const selectedPeopleIds = people.reduce((result, person) => {
	const hasAccount = person.accounts.some(({id}) => id === accountId);
	if (hasAccount) {
		result.push(person.id);
	}
	return result;
}, []);
ready
find company (exists)
const selectedPeopleIds = people.reduce((result, person) => {
	const hasAccount = person.accounts.some(({id}) => id === accountId2);
	if (hasAccount) {
		result.push(person.id);
	}
	return result;
}, []);
ready

Revisions

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