Array equality

Benchmark created on


Setup

const cnt = 10
const a = Array.from(new Array(cnt).keys())
const b = Array.from(new Array(cnt).keys()).reverse()
function compare1(a, b) {
  if (a.length !== b.length) return false
  const newA = a.sort()
  const newB = b.sort()
  return newA.join(',') === newB.join(',')
}
function compare2(a, b) {
	return a.length === b.length && new Set(a.concat(b)).size === a.length
}

Test runner

Ready to run.

Testing in
TestOps/sec
Array equality with sort
compare1(a, b)
ready
Array equality with Set
compare2(a, b)
ready
Array equality with sort equal arrays
compare1(a, a)
ready
Array equality with Set equal arrays
compare2(a, a)
ready

Revisions

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