Set equality

Benchmark created on


Setup

const a = new Set([
  'fd59243d-fd49-4641-a4d5-cdf111b795a0',
  '671a8343-1af3-479f-97e5-9f089e279866',
  '38d228e9-21b6-4591-b10f-eb3feab3cbb2',
  '011f68e0-79bd-409d-9742-33e363e777dc',
  '54ba63f2-e3c7-48dc-955b-52faef003572',
  '55de484f-ae1d-414d-862e-8c6d79ad37c2',
  '413d8333-28ed-4ffd-baf1-f8a33d53c48b',
  '7daf79e8-a29d-47c1-96b8-50c593ede03b',
  '2f625628-51b1-43ff-a3b8-678c18bfcc8d',
  'e5755075-2eb0-4475-9c32-629ddab1f0bc',
  '2004be3f-458a-411b-bb1e-5d8def09f89c',
  '48ef2e5c-71a1-43c2-b36d-6d7c73256bb8',
  '990cf164-7c71-4d74-b3b7-1aa15103ae35',
  'dbf10e1b-a422-45e9-a588-0f1ceea44c81',
  '20bc70de-0d71-4c01-9f9f-262d8d0c7593',
  'c68ab0f0-ea71-449a-a7a1-d87f97814d1b',
  'b794acfd-7f64-4108-aae3-3033f289f9a2',
  '31e26382-21b1-4cb4-9422-5ad6cf394946',
  'b1313b7d-290f-4e34-a449-65d031ee1533',
  '479cf05c-6ade-48e2-982d-62f3324d1525',
])

const b = new Set([
  '3a3c8dd1-d2b9-458b-9dc2-66282e221336',
  '8ad51b2b-c7f0-4147-89da-7e60bd69b752',
  'b04f22e5-d464-48ff-8dd6-7dae72069e9f',
  '5ce5fd5a-206f-4e48-9618-aa64701ebbc4',
  '245da3d2-c151-4729-a7d2-ee28e22613c2',
  'c8928e21-abf8-445f-a111-208ecbee6931',
  'fabb1323-9186-45c0-9584-df9c0d54b047',
  '8187e350-2d1f-4040-9c40-f175847e4fbf',
  '7dff8b77-c1a7-4dd4-b215-5987a35d4b82',
  'b027961b-6623-4979-98fd-af06e9e38969',
  'd07413cf-97d2-407d-9342-15ab7dbd1846',
  'bd92aa6a-bf88-4dc2-bf06-03dfdd48c08a',
  'b2ef23b9-f5e3-4ddf-9807-b35a535fe366',
  '223d2aed-e63f-48b1-88d0-c098fa2ebd09',
  'ebde6f25-3934-446c-b12a-e2c2cd2b48c0',
  '02aa6713-9932-488b-8f7b-39b701473863',
  '57e36ab7-a5a4-414e-9da9-e5ad1d4c2c9b',
  '28aa7490-08c0-480c-a030-773551363c34',
  '2f8384c1-9c45-46b8-89a4-3a0899616d1f',
  '8e552fe5-c199-4181-bf20-0ca3b469e771',
])

const c = new Set([
  'fd59243d-fd49-4641-a4d5-cdf111b795a0',
  '671a8343-1af3-479f-97e5-9f089e279866',
  '38d228e9-21b6-4591-b10f-eb3feab3cbb2',
  '011f68e0-79bd-409d-9742-33e363e777dc',
  '54ba63f2-e3c7-48dc-955b-52faef003572',
  '55de484f-ae1d-414d-862e-8c6d79ad37c2',
  '413d8333-28ed-4ffd-baf1-f8a33d53c48b',
  '7daf79e8-a29d-47c1-96b8-50c593ede03b',
  '2f625628-51b1-43ff-a3b8-678c18bfcc8d',
  'e5755075-2eb0-4475-9c32-629ddab1f0bc',
  '2004be3f-458a-411b-bb1e-5d8def09f89c',
  '48ef2e5c-71a1-43c2-b36d-6d7c73256bb8',
  '990cf164-7c71-4d74-b3b7-1aa15103ae35',
  'dbf10e1b-a422-45e9-a588-0f1ceea44c81',
  '20bc70de-0d71-4c01-9f9f-262d8d0c7593',
  'c68ab0f0-ea71-449a-a7a1-d87f97814d1b',
  'b794acfd-7f64-4108-aae3-3033f289f9a2',
  '28aa7490-08c0-480c-a030-773551363c34',
  '2f8384c1-9c45-46b8-89a4-3a0899616d1f',
  '8e552fe5-c199-4181-bf20-0ca3b469e771',
])


function setEq1(a, b) {
  if (a.size !== b.size) return false
  for (const item of a) {
    if (!b.has(item)) {
      return false
    }
  }
  return true
}

function setEq2(a, b) {
  if (a.size !== b.size) return false
  return a.difference(b).size === 0
}

function setEq3(a, b) {
  if (a.size !== b.size) return false
  return a.isSubsetOf(b)
}

 

Test runner

Ready to run.

Testing in
TestOps/sec
loop (disjoint sets)
setEq1(a, b)
ready
difference (disjoint sets)
setEq2(a, b)
ready
subset (disjoint sets)
setEq3(a, b)
ready
loop (overlapping sets)
setEq1(a, c)
ready
difference (overlapping sets)
setEq2(a, c)
ready
subset (overlapping sets)
setEq3(a, c)
ready

Revisions

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