set vs array (v3)

Revision 3 of this benchmark created on


Setup

const summaryRecs = [{id:1}, {id:2}];
const summarySet = new Set(summaryRecs.map(it => it.id));
const summaryArray = summaryRecs.map(it => it.id);


function testSet(id) {
	summarySet.has(id)
}

function testArraySome(id) {
	summaryRecs.some(it => it.id === id);	
}

function testArrayIncludes(id) {
	summaryArray.includes(id)
}

Test runner

Ready to run.

Testing in
TestOps/sec
Set
for (y = 0; y < 10_000; y++) {
	testSet(y);
} 
ready
Ar
for (y = 0; y < 10_000; y++) {
	testArraySome(y);
} 
ready
Array includes
for (y = 0; y < 10_000; y++) {
	testArrayIncludes(y);
} 
ready

Revisions

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