Double iteration over map

Benchmark created on


Setup

const arr1 = [{a:1, b:'abc', c: false}, {a:2, b:'bcd', c: true}, {a:4.7, b:'klz', c: true}, {a:3, b:'xyz', c: false}]

const arr2 = [{a:1, b:'abc', c: false}, {a:2, b:'bcd', c: true}, {a:4.7, b:'klz', c: true}, {a:3, b:'xyz', c: false}]

function datumCompare(dat1, dat2) {
    return dat1.a === dat2.a && dat1.b === dat2.b && dat1.c === dat2.c
  }

Test runner

Ready to run.

Testing in
TestOps/sec
Iteration
for (const datum1 of arr1) {
	const matches = arr2.some(datum2 => datumCompare(datum1, datum2))
	}
ready
Map
const datum2Map = {}

for (const datum2 of arr2) {
  datum2Map[datum2.a] = datum2
}
arr1.every(datum1 => {
  const datum2 = datum2Map[datum1.a]
  return datumCompare(datum1, datum2)
})
ready

Revisions

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