Set lookup vs Filter+some (v2)

Revision 2 of this benchmark created on


Setup

let big1 = Array.from({length: 1000}).map((_,i) => ({id: i}));
let big2 = Array.from({length: 1000}).map((_,i) => ({id: i*3}));

let small1 = big1.slice(0, 100);
let small2 = big2.slice(0, 100);


let mini1 = big1.slice(0, 10);
let mini2 = big2.slice(0, 10);

function setCompare(oldValues, newValues) {
	let newSet = new Set(newValues.map(item => item.id));
  	return oldValues.filter(item => !newSet.has(item.id));
}
function filterSomeCompare(oldValues, newValues) {
	return oldValues.filter(o => !newValues.some(n => n.id === o.id));
}

Test runner

Ready to run.

Testing in
TestOps/sec
Set (mini)
setCompare(mini1,mini2)
ready
Filter/Some (mini)
filterSomeCompare(mini1,mini2)
ready
Set (small)
setCompare(small1,small2)
ready
Filter/Some (small)
filterSomeCompare(small1,small2)
ready
Set (big)
setCompare(big1,big2)
ready
Filter/Some (big)
filterSomeCompare(big1, big2)
ready

Revisions

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