13
13
import TestsUtils
14
14
15
15
let size = 400
16
- let overlap = 100
16
+ let half = size / 2
17
+ let quarter = size / 4
17
18
19
+ // Construction kit for sets with 25% overlap
18
20
let setAB = Set ( 0 ..< size) // 0 ..< 400
19
21
let setCD = Set ( size ..< 2 * size) // 400 ..< 800
20
- let setBC = Set ( size - overlap ..< 2 * size - overlap ) // 300 ..< 700
21
- let setB = Set ( size - overlap ..< size) // 300 ..< 400
22
+ let setBC = Set ( size - quarter ..< 2 * size - quarter ) // 300 ..< 700
23
+ let setB = Set ( size - quarter ..< size) // 300 ..< 400
22
24
23
25
let setOAB = Set ( setAB. map ( Box . init) )
24
26
let setOCD = Set ( setCD. map ( Box . init) )
25
27
let setOBC = Set ( setBC. map ( Box . init) )
26
28
let setOB = Set ( setB. map ( Box . init) )
27
29
28
- let countAC = 2 * ( size - overlap) // 600
29
- let countABC = 2 * size - overlap // 700
30
- let countABCD = 2 * size // 800
31
- let countB = overlap // 100
30
+ let countA = size - quarter // 300
31
+ let countB = quarter // 100
32
+ let countC = countA // 300
33
+ let countD = countB // 100
34
+
35
+ let countAB = size // 400
36
+ let countAC = countA + countC // 600
37
+ let countABC = countA + countB + countC // 700
38
+ let countABCD = countA + countB + countC + countD // 800
39
+
40
+ // Construction kit for sets with 50% overlap
41
+ let setXY = Set ( 0 ..< size) // 0 ..< 400
42
+ let setYZ = Set ( half ..< size + half) // 200 ..< 600
43
+ let setY = Set ( half ..< size) // 200 ..< 400
44
+
45
+ // Two sets with 100% overlap, but different bucket counts (let's not make it
46
+ // too easy...)
47
+ let setP = Set ( 0 ..< size)
48
+ let setQ : Set < Int > = {
49
+ var set = Set ( 0 ..< size)
50
+ set. reserveCapacity ( 2 * size)
51
+ return set
52
+ } ( )
32
53
33
54
public let SetTests = [
55
+ // Legacy benchmarks, kept for continuity with previous releases.
34
56
BenchmarkInfo (
35
- name: " SetExclusiveOr " ,
36
- runFunction: { n in run_SetExclusiveOr ( setAB, setCD, countABCD, 100 * n) } ,
57
+ name: " SetExclusiveOr " , // ~"SetSymmetricDifferenceInt0"
58
+ runFunction: { n in run_SetSymmetricDifferenceInt ( setAB, setCD, countABCD, 100 * n) } ,
37
59
tags: [ . validation, . api, . Set] ,
38
60
setUpFunction: { blackHole ( [ setAB, setCD] ) } ) ,
39
61
BenchmarkInfo (
40
- name: " SetExclusiveOr2 " ,
41
- runFunction: { n in run_SetExclusiveOr ( setAB , setBC , countAC , 10 * n) } ,
62
+ name: " SetExclusiveOr_OfObjects " , // ~"SetSymmetricDifferenceBox0"
63
+ runFunction: { n in run_SetSymmetricDifferenceBox ( setOAB , setOCD , countABCD , 100 * n) } ,
42
64
tags: [ . validation, . api, . Set] ,
43
- setUpFunction: { blackHole ( [ setAB , setBC ] ) } ) ,
65
+ setUpFunction: { blackHole ( [ setOAB , setOCD ] ) } ) ,
44
66
BenchmarkInfo (
45
- name: " SetExclusiveOr_OfObjects " ,
46
- runFunction: { n in run_SetExclusiveOr_OfObjects ( setOAB , setOCD , countABCD , 100 * n) } ,
67
+ name: " SetIntersect " , // ~"SetIntersectionInt0"
68
+ runFunction: { n in run_SetIntersectionInt ( setAB , setCD , 0 , 100 * n) } ,
47
69
tags: [ . validation, . api, . Set] ,
48
- setUpFunction: { blackHole ( [ setOAB , setOCD ] ) } ) ,
70
+ setUpFunction: { blackHole ( [ setAB , setCD ] ) } ) ,
49
71
BenchmarkInfo (
50
- name: " SetExclusiveOr2_OfObjects " ,
51
- runFunction: { n in run_SetExclusiveOr_OfObjects ( setOAB , setOBC , countAC , 10 * n) } ,
72
+ name: " SetUnion " , // ~"SetUnionInt0"
73
+ runFunction: { n in run_SetUnionInt ( setAB , setCD , countABCD , 100 * n) } ,
52
74
tags: [ . validation, . api, . Set] ,
53
- setUpFunction: { blackHole ( [ setOAB, setOBC] ) } ) ,
75
+ setUpFunction: { blackHole ( [ setAB, setCD] ) } ) ,
76
+ BenchmarkInfo (
77
+ name: " SetUnion_OfObjects " , // ~"SetUnionBox0"
78
+ runFunction: { n in run_SetUnionBox ( setOAB, setOCD, countABCD, 100 * n) } ,
79
+ tags: [ . validation, . api, . Set] ,
80
+ setUpFunction: { blackHole ( [ setOAB, setOCD] ) } ) ,
54
81
82
+ // Mnemonic: number after name is percentage of common elements in input sets.
55
83
BenchmarkInfo (
56
- name: " SetIntersect " ,
57
- runFunction: { n in run_SetIntersect ( setAB, setCD, 0 , 100 * n) } ,
84
+ name: " SetIsSubsetInt0 " ,
85
+ runFunction: { n in run_SetIsSubsetInt ( setAB, setCD, false , 5000 * n) } ,
58
86
tags: [ . validation, . api, . Set] ,
59
87
setUpFunction: { blackHole ( [ setAB, setCD] ) } ) ,
60
88
BenchmarkInfo (
61
- name: " SetIntersect2 " ,
62
- runFunction: { n in run_SetIntersect ( setAB , setBC , countB , 10 * n) } ,
89
+ name: " SetIsSubsetBox0 " ,
90
+ runFunction: { n in run_SetIsSubsetBox ( setOAB , setOCD , false , 5000 * n) } ,
63
91
tags: [ . validation, . api, . Set] ,
64
- setUpFunction: { blackHole ( [ setAB, setBC] ) } ) ,
92
+ setUpFunction: { blackHole ( [ setOAB, setOCD] ) } ) ,
93
+ BenchmarkInfo (
94
+ name: " SetIsSubsetInt25 " ,
95
+ runFunction: { n in run_SetIsSubsetInt ( setB, setAB, true , 50 * n) } ,
96
+ tags: [ . validation, . api, . Set] ,
97
+ setUpFunction: { blackHole ( [ setB, setAB] ) } ) ,
98
+ BenchmarkInfo (
99
+ name: " SetIsSubsetBox25 " ,
100
+ runFunction: { n in run_SetIsSubsetBox ( setOB, setOAB, true , 50 * n) } ,
101
+ tags: [ . validation, . api, . Set] ,
102
+ setUpFunction: { blackHole ( [ setOB, setOAB] ) } ) ,
103
+ BenchmarkInfo (
104
+ name: " SetIsSubsetInt50 " ,
105
+ runFunction: { n in run_SetIsSubsetInt ( setY, setXY, true , 50 * n) } ,
106
+ tags: [ . validation, . api, . Set] ,
107
+ setUpFunction: { blackHole ( [ setY, setXY] ) } ) ,
65
108
BenchmarkInfo (
66
- name: " SetIntersect_OfObjects " ,
67
- runFunction: { n in run_SetIntersect_OfObjects ( setOAB, setOCD, 0 , 100 * n) } ,
109
+ name: " SetIsSubsetInt100 " ,
110
+ runFunction: { n in run_SetIsSubsetInt ( setP, setQ, true , 50 * n) } ,
111
+ tags: [ . validation, . api, . Set] ,
112
+ setUpFunction: { blackHole ( [ setP, setQ] ) } ) ,
113
+
114
+ BenchmarkInfo (
115
+ name: " SetSymmetricDifferenceInt0 " ,
116
+ runFunction: { n in run_SetSymmetricDifferenceInt ( setAB, setCD, countABCD, 10 * n) } ,
117
+ tags: [ . validation, . api, . Set] ,
118
+ setUpFunction: { blackHole ( [ setAB, setCD] ) } ) ,
119
+ BenchmarkInfo (
120
+ name: " SetSymmetricDifferenceBox0 " ,
121
+ runFunction: { n in run_SetSymmetricDifferenceBox ( setOAB, setOCD, countABCD, 10 * n) } ,
68
122
tags: [ . validation, . api, . Set] ,
69
123
setUpFunction: { blackHole ( [ setOAB, setOCD] ) } ) ,
70
124
BenchmarkInfo (
71
- name: " SetIntersect2_OfObjects " ,
72
- runFunction: { n in run_SetIntersect_OfObjects ( setOAB, setOBC, countB, 10 * n) } ,
125
+ name: " SetSymmetricDifferenceInt25 " ,
126
+ runFunction: { n in run_SetSymmetricDifferenceInt ( setAB, setBC, countAC, 10 * n) } ,
127
+ tags: [ . validation, . api, . Set] ,
128
+ setUpFunction: { blackHole ( [ setAB, setBC] ) } ) ,
129
+ BenchmarkInfo (
130
+ name: " SetSymmetricDifferenceBox25 " ,
131
+ runFunction: { n in run_SetSymmetricDifferenceBox ( setOAB, setOBC, countAC, 10 * n) } ,
73
132
tags: [ . validation, . api, . Set] ,
74
133
setUpFunction: { blackHole ( [ setOAB, setOBC] ) } ) ,
134
+ BenchmarkInfo (
135
+ name: " SetSymmetricDifferenceInt50 " ,
136
+ runFunction: { n in run_SetSymmetricDifferenceInt ( setXY, setYZ, size, 10 * n) } ,
137
+ tags: [ . validation, . api, . Set] ,
138
+ setUpFunction: { blackHole ( [ setXY, setYZ] ) } ) ,
139
+ BenchmarkInfo (
140
+ name: " SetSymmetricDifferenceInt100 " ,
141
+ runFunction: { n in run_SetSymmetricDifferenceInt ( setP, setQ, 0 , 10 * n) } ,
142
+ tags: [ . validation, . api, . Set] ,
143
+ setUpFunction: { blackHole ( [ setP, setQ] ) } ) ,
75
144
76
145
BenchmarkInfo (
77
- name: " SetIsSubsetOf " ,
78
- runFunction: { n in run_SetIsSubsetOf ( setAB, setCD, false , 5000 * n) } ,
146
+ name: " SetIntersectionInt0 " ,
147
+ runFunction: { n in run_SetIntersectionInt ( setAB, setCD, 0 , 10 * n) } ,
79
148
tags: [ . validation, . api, . Set] ,
80
149
setUpFunction: { blackHole ( [ setAB, setCD] ) } ) ,
81
150
BenchmarkInfo (
82
- name: " SetIsSubsetOf2 " ,
83
- runFunction: { n in run_SetIsSubsetOf ( setB , setAB , true , 50 * n) } ,
151
+ name: " SetIntersectionBox0 " ,
152
+ runFunction: { n in run_SetIntersectionBox ( setOAB , setOCD , 0 , 10 * n) } ,
84
153
tags: [ . validation, . api, . Set] ,
85
- setUpFunction: { blackHole ( [ setB , setAB ] ) } ) ,
154
+ setUpFunction: { blackHole ( [ setOAB , setOCD ] ) } ) ,
86
155
BenchmarkInfo (
87
- name: " SetIsSubsetOf_OfObjects " ,
88
- runFunction: { n in run_SetIsSubsetOf_OfObjects ( setOAB , setOCD , false , 5000 * n) } ,
156
+ name: " SetIntersectionInt25 " ,
157
+ runFunction: { n in run_SetIntersectionInt ( setAB , setBC , countB , 10 * n) } ,
89
158
tags: [ . validation, . api, . Set] ,
90
- setUpFunction: { blackHole ( [ setOAB , setOCD ] ) } ) ,
159
+ setUpFunction: { blackHole ( [ setAB , setBC ] ) } ) ,
91
160
BenchmarkInfo (
92
- name: " SetIsSubsetOf2_OfObjects " ,
93
- runFunction: { n in run_SetIsSubsetOf_OfObjects ( setOB , setOAB , true , 50 * n) } ,
161
+ name: " SetIntersectionBox25 " ,
162
+ runFunction: { n in run_SetIntersectionBox ( setOAB , setOBC , countB , 10 * n) } ,
94
163
tags: [ . validation, . api, . Set] ,
95
- setUpFunction: { blackHole ( [ setOB, setOAB] ) } ) ,
164
+ setUpFunction: { blackHole ( [ setOAB, setOBC] ) } ) ,
165
+ BenchmarkInfo (
166
+ name: " SetIntersectionInt50 " ,
167
+ runFunction: { n in run_SetIntersectionInt ( setXY, setYZ, half, 10 * n) } ,
168
+ tags: [ . validation, . api, . Set] ,
169
+ setUpFunction: { blackHole ( [ setXY, setYZ] ) } ) ,
170
+ BenchmarkInfo (
171
+ name: " SetIntersectionInt100 " ,
172
+ runFunction: { n in run_SetIntersectionInt ( setP, setQ, size, 10 * n) } ,
173
+ tags: [ . validation, . api, . Set] ,
174
+ setUpFunction: { blackHole ( [ setP, setQ] ) } ) ,
96
175
97
176
BenchmarkInfo (
98
- name: " SetUnion " ,
99
- runFunction: { n in run_SetUnion ( setAB, setCD, countABCD, 100 * n) } ,
177
+ name: " SetUnionInt0 " ,
178
+ runFunction: { n in run_SetUnionInt ( setAB, setCD, countABCD, 10 * n) } ,
100
179
tags: [ . validation, . api, . Set] ,
101
180
setUpFunction: { blackHole ( [ setAB, setCD] ) } ) ,
102
181
BenchmarkInfo (
103
- name: " SetUnion2 " ,
104
- runFunction: { n in run_SetUnion ( setAB, setBC, countABC, 10 * n) } ,
182
+ name: " SetUnionBox0 " ,
183
+ runFunction: { n in run_SetUnionBox ( setOAB, setOCD, countABCD, 10 * n) } ,
184
+ tags: [ . validation, . api, . Set] ,
185
+ setUpFunction: { blackHole ( [ setOAB, setOCD] ) } ) ,
186
+ BenchmarkInfo (
187
+ name: " SetUnionInt25 " ,
188
+ runFunction: { n in run_SetUnionInt ( setAB, setBC, countABC, 10 * n) } ,
105
189
tags: [ . validation, . api, . Set] ,
106
190
setUpFunction: { blackHole ( [ setAB, setBC] ) } ) ,
107
191
BenchmarkInfo (
108
- name: " SetUnion_OfObjects " ,
109
- runFunction: { n in run_SetUnion_OfObjects ( setOAB, setOCD, countABCD, 100 * n) } ,
192
+ name: " SetUnionBox25 " ,
193
+ runFunction: { n in run_SetUnionBox ( setOAB, setOBC, countABC, 10 * n) } ,
194
+ tags: [ . validation, . api, . Set] ,
195
+ setUpFunction: { blackHole ( [ setOAB, setOBC] ) } ) ,
196
+ BenchmarkInfo (
197
+ name: " SetUnionInt50 " ,
198
+ runFunction: { n in run_SetUnionInt ( setXY, setYZ, size + half, 10 * n) } ,
199
+ tags: [ . validation, . api, . Set] ,
200
+ setUpFunction: { blackHole ( [ setXY, setYZ] ) } ) ,
201
+ BenchmarkInfo (
202
+ name: " SetUnionInt100 " ,
203
+ runFunction: { n in run_SetUnionInt ( setP, setQ, size, 10 * n) } ,
204
+ tags: [ . validation, . api, . Set] ,
205
+ setUpFunction: { blackHole ( [ setP, setQ] ) } ) ,
206
+
207
+ BenchmarkInfo (
208
+ name: " SetSubtractingInt0 " ,
209
+ runFunction: { n in run_SetSubtractingInt ( setAB, setCD, countAB, 10 * n) } ,
210
+ tags: [ . validation, . api, . Set] ,
211
+ setUpFunction: { blackHole ( [ setAB, setCD] ) } ) ,
212
+ BenchmarkInfo (
213
+ name: " SetSubtractingBox0 " ,
214
+ runFunction: { n in run_SetSubtractingBox ( setOAB, setOCD, countAB, 10 * n) } ,
110
215
tags: [ . validation, . api, . Set] ,
111
216
setUpFunction: { blackHole ( [ setOAB, setOCD] ) } ) ,
112
217
BenchmarkInfo (
113
- name: " SetUnion2_OfObjects " ,
114
- runFunction: { n in run_SetUnion_OfObjects ( setOAB, setOBC, countABC, 10 * n) } ,
218
+ name: " SetSubtractingInt25 " ,
219
+ runFunction: { n in run_SetSubtractingInt ( setAB, setBC, countA, 10 * n) } ,
220
+ tags: [ . validation, . api, . Set] ,
221
+ setUpFunction: { blackHole ( [ setAB, setBC] ) } ) ,
222
+ BenchmarkInfo (
223
+ name: " SetSubtractingBox25 " ,
224
+ runFunction: { n in run_SetSubtractingBox ( setOAB, setOBC, countA, 10 * n) } ,
115
225
tags: [ . validation, . api, . Set] ,
116
226
setUpFunction: { blackHole ( [ setOAB, setOBC] ) } ) ,
227
+ BenchmarkInfo (
228
+ name: " SetSubtractingInt50 " ,
229
+ runFunction: { n in run_SetSubtractingInt ( setXY, setYZ, half, 10 * n) } ,
230
+ tags: [ . validation, . api, . Set] ,
231
+ setUpFunction: { blackHole ( [ setXY, setYZ] ) } ) ,
232
+ BenchmarkInfo (
233
+ name: " SetSubtractingInt100 " ,
234
+ runFunction: { n in run_SetSubtractingInt ( setP, setQ, 0 , 10 * n) } ,
235
+ tags: [ . validation, . api, . Set] ,
236
+ setUpFunction: { blackHole ( [ setP, setQ] ) } ) ,
117
237
]
118
238
119
239
@inline ( never)
120
- public func run_SetIsSubsetOf (
240
+ public func run_SetIsSubsetInt (
121
241
_ a: Set < Int > ,
122
242
_ b: Set < Int > ,
123
243
_ r: Bool ,
@@ -129,7 +249,7 @@ public func run_SetIsSubsetOf(
129
249
}
130
250
131
251
@inline ( never)
132
- public func run_SetExclusiveOr (
252
+ public func run_SetSymmetricDifferenceInt (
133
253
_ a: Set < Int > ,
134
254
_ b: Set < Int > ,
135
255
_ r: Int ,
@@ -141,7 +261,7 @@ public func run_SetExclusiveOr(
141
261
}
142
262
143
263
@inline ( never)
144
- public func run_SetUnion (
264
+ public func run_SetUnionInt (
145
265
_ a: Set < Int > ,
146
266
_ b: Set < Int > ,
147
267
_ r: Int ,
@@ -153,7 +273,7 @@ public func run_SetUnion(
153
273
}
154
274
155
275
@inline ( never)
156
- public func run_SetIntersect (
276
+ public func run_SetIntersectionInt (
157
277
_ a: Set < Int > ,
158
278
_ b: Set < Int > ,
159
279
_ r: Int ,
@@ -164,6 +284,18 @@ public func run_SetIntersect(
164
284
}
165
285
}
166
286
287
+ @inline ( never)
288
+ public func run_SetSubtractingInt(
289
+ _ a: Set < Int > ,
290
+ _ b: Set < Int > ,
291
+ _ r: Int ,
292
+ _ n: Int ) {
293
+ for _ in 0 ..< n {
294
+ let and = a. subtracting ( identity ( b) )
295
+ CheckResults ( and. count == r)
296
+ }
297
+ }
298
+
167
299
class Box < T : Hashable > : Hashable {
168
300
var value : T
169
301
@@ -181,7 +313,7 @@ class Box<T : Hashable> : Hashable {
181
313
}
182
314
183
315
@inline ( never)
184
- func run_SetIsSubsetOf_OfObjects (
316
+ func run_SetIsSubsetBox (
185
317
_ a: Set < Box < Int > > ,
186
318
_ b: Set < Box < Int > > ,
187
319
_ r: Bool ,
@@ -193,7 +325,7 @@ func run_SetIsSubsetOf_OfObjects(
193
325
}
194
326
195
327
@inline ( never)
196
- func run_SetExclusiveOr_OfObjects (
328
+ func run_SetSymmetricDifferenceBox (
197
329
_ a: Set < Box < Int > > ,
198
330
_ b: Set < Box < Int > > ,
199
331
_ r: Int ,
@@ -205,7 +337,7 @@ func run_SetExclusiveOr_OfObjects(
205
337
}
206
338
207
339
@inline ( never)
208
- func run_SetUnion_OfObjects (
340
+ func run_SetUnionBox (
209
341
_ a: Set < Box < Int > > ,
210
342
_ b: Set < Box < Int > > ,
211
343
_ r: Int ,
@@ -217,7 +349,7 @@ func run_SetUnion_OfObjects(
217
349
}
218
350
219
351
@inline ( never)
220
- func run_SetIntersect_OfObjects (
352
+ func run_SetIntersectionBox (
221
353
_ a: Set < Box < Int > > ,
222
354
_ b: Set < Box < Int > > ,
223
355
_ r: Int ,
@@ -227,3 +359,15 @@ func run_SetIntersect_OfObjects(
227
359
CheckResults ( and. count == r)
228
360
}
229
361
}
362
+
363
+ @inline ( never)
364
+ func run_SetSubtractingBox(
365
+ _ a: Set < Box < Int > > ,
366
+ _ b: Set < Box < Int > > ,
367
+ _ r: Int ,
368
+ _ n: Int ) {
369
+ for _ in 0 ..< n {
370
+ let and = a. subtracting ( b)
371
+ CheckResults ( and. count == r)
372
+ }
373
+ }
0 commit comments