@@ -26,28 +26,39 @@ public let WordCount = [
26
26
BenchmarkInfo (
27
27
name: " WordSplitASCII " ,
28
28
runFunction: run_WordSplitASCII,
29
- tags: [ . validation, . api, . String, . algorithm] ) ,
29
+ tags: [ . validation, . api, . String, . algorithm] ,
30
+ setUpFunction: { buildWorkload ( ) }
31
+ ) ,
30
32
BenchmarkInfo (
31
33
name: " WordSplitUTF16 " ,
32
34
runFunction: run_WordSplitUTF16,
33
- tags: [ . validation, . api, . String, . algorithm] ) ,
35
+ tags: [ . validation, . api, . String, . algorithm] ,
36
+ setUpFunction: { buildWorkload ( ) }
37
+ ) ,
34
38
BenchmarkInfo (
35
39
name: " WordCountUniqueASCII " ,
36
40
runFunction: run_WordCountUniqueASCII,
37
- tags: [ . validation, . api, . String, . Dictionary, . algorithm] ) ,
41
+ tags: [ . validation, . api, . String, . Dictionary, . algorithm] ,
42
+ setUpFunction: { buildWorkload ( ) }
43
+ ) ,
38
44
BenchmarkInfo (
39
45
name: " WordCountUniqueUTF16 " ,
40
46
runFunction: run_WordCountUniqueUTF16,
41
- tags: [ . validation, . api, . String, . Dictionary, . algorithm] ) ,
47
+ tags: [ . validation, . api, . String, . Dictionary, . algorithm] ,
48
+ setUpFunction: { buildWorkload ( ) }
49
+ ) ,
42
50
BenchmarkInfo (
43
51
name: " WordCountHistogramASCII " ,
44
52
runFunction: run_WordCountHistogramASCII,
45
- tags: [ . validation, . api, . String, . Dictionary, . algorithm] ) ,
53
+ tags: [ . validation, . api, . String, . Dictionary, . algorithm] ,
54
+ setUpFunction: { buildWorkload ( ) }
55
+ ) ,
46
56
BenchmarkInfo (
47
57
name: " WordCountHistogramUTF16 " ,
48
58
runFunction: run_WordCountHistogramUTF16,
49
- tags: [ . validation, . api, . String, . Dictionary, . algorithm] ) ,
50
-
59
+ tags: [ . validation, . api, . String, . Dictionary, . algorithm] ,
60
+ setUpFunction: { buildWorkload ( ) }
61
+ ) ,
51
62
]
52
63
53
64
let asciiText = """
@@ -129,6 +140,13 @@ source code and over 20 GB of disk space for thé build artifacts. A clean build
129
140
can take multiple hours, but incremental builds will finish much faster.
130
141
"""
131
142
143
+ @inline ( never)
144
+ func buildWorkload( ) {
145
+ blackHole ( someAlphanumerics)
146
+ blackHole ( asciiWords)
147
+ blackHole ( utf16Words)
148
+ }
149
+
132
150
// A partial set of Unicode alphanumeric characters. (ASCII letters with at most
133
151
// one diacritic (of a limited selection), plus ASCII digits.)
134
152
let someAlphanumerics : Set < Character > = {
@@ -184,16 +202,18 @@ struct Words: IteratorProtocol, Sequence {
184
202
@inline ( never)
185
203
public func run_WordSplitASCII( _ N: Int ) {
186
204
for _ in 1 ... 10 * N {
187
- let count = Array ( Words ( identity ( asciiText) ) ) . count
188
- CheckResults ( count == 280 )
205
+ let words = Array ( Words ( identity ( asciiText) ) )
206
+ CheckResults ( words. count == 280 )
207
+ blackHole ( words)
189
208
}
190
209
}
191
210
192
211
@inline ( never)
193
212
public func run_WordSplitUTF16( _ N: Int ) {
194
213
for _ in 1 ... 10 * N {
195
- let count = Array ( Words ( identity ( utf16Text) ) ) . count
196
- CheckResults ( count == 280 )
214
+ let words = Array ( Words ( identity ( utf16Text) ) )
215
+ CheckResults ( words. count == 280 )
216
+ blackHole ( words)
197
217
}
198
218
}
199
219
0 commit comments