Set lookup vs Filter+some

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 = Array.from({length: 100}).map((_,i) => ({id: i}))
let small2 = Array.from({length: 100}).map((_,i) => ({id: i*3}))


let mini1 = Array.from({length: 10}).map((_,i) => ({id: i}))
let mini2 = Array.from({length: 10}).map((_,i) => ({id: i*3}))

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.