Skip to content

Commit c3c1e6d

Browse files
[Benchmarks][stdlib] Adding an extra benchmark for set isDisjoint for disjoint sets of different size
1 parent 4164b2e commit c3c1e6d

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

benchmark/single-source/SetTests.swift

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,13 @@ let setAB = Set(0 ..< size) // 0 ..< 400
2525
let setCD = Set(size ..< 2 * size) // 400 ..< 800
2626
let setBC = Set(size - quarter ..< 2 * size - quarter) // 300 ..< 700
2727
let setB = Set(size - quarter ..< size) // 300 ..< 400
28+
let setCDS = Set(size ..< (size + (size/4))) // 400 ..< 500
2829

2930
let setOAB = Set(setAB.map(Box.init))
3031
let setOCD = Set(setCD.map(Box.init))
3132
let setOBC = Set(setBC.map(Box.init))
3233
let setOB = Set(setB.map(Box.init))
34+
let setOCDS = Set(setCDS.map(Box.init))
3335

3436
let countA = size - quarter // 300
3537
let countB = quarter // 100
@@ -368,6 +370,16 @@ public let SetTests = [
368370
runFunction: { n in run_SetIsDisjointBox(setOAB, setOCD, true, 50 * n) },
369371
tags: [.validation, .api, .Set],
370372
setUpFunction: { blackHole([setOAB, setOCD]) }),
373+
BenchmarkInfo(
374+
name: "Set.isDisjoint.Smaller.Int0",
375+
runFunction: { n in run_SetIsDisjointIntCommutative(setAB, setCDS, true, 50 * n) },
376+
tags: [.validation, .api, .Set],
377+
setUpFunction: { blackHole([setAB, setCDS]) }),
378+
BenchmarkInfo(
379+
name: "Set.isDisjoint.Smaller.Box0",
380+
runFunction: { n in run_SetIsDisjointBoxCommutative(setOAB, setOCDS, true, 50 * n) },
381+
tags: [.validation, .api, .Set],
382+
setUpFunction: { blackHole([setOAB, setOCDS]) }),
371383
BenchmarkInfo(
372384
name: "Set.isDisjoint.Int25",
373385
runFunction: { n in run_SetIsDisjointInt(setB, setAB, false, 5000 * n) },
@@ -891,6 +903,22 @@ public func run_SetIsDisjointInt(
891903
}
892904
}
893905

906+
// Run isDisjoint Int switching the order of the two sets.
907+
@inline(never)
908+
public func run_SetIsDisjointIntCommutative(
909+
_ a: Set<Int>,
910+
_ b: Set<Int>,
911+
_ r: Bool,
912+
_ n: Int) {
913+
for _ in 0 ..< n {
914+
let isDisjointA = a.isDisjoint(with: identity(b))
915+
CheckResults(isDisjointA == r)
916+
917+
let isDisjointB = b.isDisjoint(with: identity(a))
918+
CheckResults(isDisjointB == r)
919+
}
920+
}
921+
894922
@inline(never)
895923
public func run_SetIsDisjointSeqInt(
896924
_ a: Set<Int>,
@@ -1091,6 +1119,22 @@ func run_SetIsDisjointBox(
10911119
}
10921120
}
10931121

1122+
// Run isDisjoint Box switching the order of the two sets.
1123+
@inline(never)
1124+
func run_SetIsDisjointBoxCommutative(
1125+
_ a: Set<Box<Int>>,
1126+
_ b: Set<Box<Int>>,
1127+
_ r: Bool,
1128+
_ n: Int) {
1129+
for _ in 0 ..< n {
1130+
let isDisjointA = a.isDisjoint(with: identity(b))
1131+
CheckResults(isDisjointA == r)
1132+
1133+
let isDisjointB = b.isDisjoint(with: identity(a))
1134+
CheckResults(isDisjointB == r)
1135+
}
1136+
}
1137+
10941138
@inline(never)
10951139
func run_SetIsDisjointSeqBox(
10961140
_ a: Set<Box<Int>>,

0 commit comments

Comments
 (0)