List IDs comparison (v2)

Revision 2 of this benchmark created on


Setup

const a = [...new Array(10000)].fill().map((_, i) => i)
const b = [...new Array(10000)].fill().map((_, i) => i)

const idListsMatch = (one, two) =>
  one.length === two.length && one.every(id => two.includes(id))
  
const idListsMatch2 = (one, two) => {
  if (one.length !== two.length) {
    return false
  }
  const lookup = new Set(one)
  return two.every(id => lookup.has(id))
}

Test runner

Ready to run.

Testing in
TestOps/sec
Array
idListsMatch(a, b)
ready
Set
idListsMatch2(a, b)
ready

Revisions

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