@@ -23,25 +23,29 @@ public let CharacterPropertiesFetch = BenchmarkInfo(
23
23
name: " CharacterPropertiesFetch " ,
24
24
runFunction: run_CharacterPropertiesFetch,
25
25
tags: [ . validation, . api, . String] ,
26
- setUpFunction: { blackHole ( workload) } )
26
+ setUpFunction: { blackHole ( workload) } ,
27
+ legacyFactor: 10 )
27
28
28
29
public let CharacterPropertiesStashed = BenchmarkInfo (
29
30
name: " CharacterPropertiesStashed " ,
30
31
runFunction: run_CharacterPropertiesStashed,
31
32
tags: [ . validation, . api, . String] ,
32
- setUpFunction: { setupStash ( ) } )
33
+ setUpFunction: { setupStash ( ) } ,
34
+ legacyFactor: 10 )
33
35
34
36
public let CharacterPropertiesStashedMemo = BenchmarkInfo (
35
37
name: " CharacterPropertiesStashedMemo " ,
36
38
runFunction: run_CharacterPropertiesStashedMemo,
37
39
tags: [ . validation, . api, . String] ,
38
- setUpFunction: { setupMemo ( ) } )
40
+ setUpFunction: { setupMemo ( ) } ,
41
+ legacyFactor: 10 )
39
42
40
43
public let CharacterPropertiesPrecomputed = BenchmarkInfo (
41
44
name: " CharacterPropertiesPrecomputed " ,
42
45
runFunction: run_CharacterPropertiesPrecomputed,
43
46
tags: [ . validation, . api, . String] ,
44
- setUpFunction: { setupPrecomputed ( ) } )
47
+ setUpFunction: { setupPrecomputed ( ) } ,
48
+ legacyFactor: 10 )
45
49
46
50
extension Character {
47
51
var firstScalar : UnicodeScalar { return unicodeScalars. first! }
@@ -253,8 +257,8 @@ func setupMemo() {
253
257
}
254
258
255
259
// Precompute whole scalar set
256
- func precompute( _ charSet: CharacterSet ) -> Set < UInt32 > {
257
- var result = Set < UInt32 > ( )
260
+ func precompute( _ charSet: CharacterSet , capacity : Int ) -> Set < UInt32 > {
261
+ var result = Set < UInt32 > ( minimumCapacity : capacity )
258
262
for plane in 0 ... 0x10 {
259
263
guard charSet. hasMember ( inPlane: UInt8 ( plane) ) else { continue }
260
264
let offset = plane &* 0x1_0000
@@ -267,43 +271,53 @@ func precompute(_ charSet: CharacterSet) -> Set<UInt32> {
267
271
}
268
272
return result
269
273
}
270
- var controlCharactersPrecomputed : Set < UInt32 > = precompute ( controlCharacters)
274
+ var controlCharactersPrecomputed : Set < UInt32 > =
275
+ precompute ( controlCharacters, capacity: 24951 )
271
276
func isControlPrecomputed( _ c: Character ) -> Bool {
272
277
return controlCharactersPrecomputed. contains ( c. firstScalar. value)
273
278
}
274
- var alphanumericsPrecomputed : Set < UInt32 > = precompute ( alphanumerics)
279
+ var alphanumericsPrecomputed : Set < UInt32 > =
280
+ precompute ( alphanumerics, capacity: 122647 )
275
281
func isAlphanumericPrecomputed( _ c: Character ) -> Bool {
276
282
return alphanumericsPrecomputed. contains ( c. firstScalar. value)
277
283
}
278
- var lowercaseLettersPrecomputed : Set < UInt32 > = precompute ( lowercaseLetters)
284
+ var lowercaseLettersPrecomputed : Set < UInt32 > =
285
+ precompute ( lowercaseLetters, capacity: 2063 )
279
286
func isLowercasePrecomputed( _ c: Character ) -> Bool {
280
287
return lowercaseLettersPrecomputed. contains ( c. firstScalar. value)
281
288
}
282
- var punctuationCharactersPrecomputed : Set < UInt32 > = precompute ( punctuationCharacters)
289
+ var punctuationCharactersPrecomputed : Set < UInt32 > =
290
+ precompute ( punctuationCharacters, capacity: 770 )
283
291
func isPunctuationPrecomputed( _ c: Character ) -> Bool {
284
292
return punctuationCharactersPrecomputed. contains ( c. firstScalar. value)
285
293
}
286
- var whitespacesPrecomputed : Set < UInt32 > = precompute ( whitespaces)
294
+ var whitespacesPrecomputed : Set < UInt32 > =
295
+ precompute ( whitespaces, capacity: 19 )
287
296
func isWhitespacePrecomputed( _ c: Character ) -> Bool {
288
297
return whitespacesPrecomputed. contains ( c. firstScalar. value)
289
298
}
290
- var lettersPrecomputed : Set < UInt32 > = precompute ( letters)
299
+ var lettersPrecomputed : Set < UInt32 > =
300
+ precompute ( letters, capacity: 121145 )
291
301
func isLetterPrecomputed( _ c: Character ) -> Bool {
292
302
return lettersPrecomputed. contains ( c. firstScalar. value)
293
303
}
294
- var uppercaseLettersPrecomputed : Set < UInt32 > = precompute ( uppercaseLetters)
304
+ var uppercaseLettersPrecomputed : Set < UInt32 > =
305
+ precompute ( uppercaseLetters, capacity: 1733 )
295
306
func isUppercasePrecomputed( _ c: Character ) -> Bool {
296
307
return uppercaseLettersPrecomputed. contains ( c. firstScalar. value)
297
308
}
298
- var decimalDigitsPrecomputed : Set < UInt32 > = precompute ( decimalDigits)
309
+ var decimalDigitsPrecomputed : Set < UInt32 > =
310
+ precompute ( decimalDigits, capacity: 590 )
299
311
func isDecimalPrecomputed( _ c: Character ) -> Bool {
300
312
return decimalDigitsPrecomputed. contains ( c. firstScalar. value)
301
313
}
302
- var newlinesPrecomputed : Set < UInt32 > = precompute ( newlines)
314
+ var newlinesPrecomputed : Set < UInt32 > =
315
+ precompute ( newlines, capacity: 7 )
303
316
func isNewlinePrecomputed( _ c: Character ) -> Bool {
304
317
return newlinesPrecomputed. contains ( c. firstScalar. value)
305
318
}
306
- var capitalizedLettersPrecomputed : Set < UInt32 > = precompute ( capitalizedLetters)
319
+ var capitalizedLettersPrecomputed : Set < UInt32 > =
320
+ precompute ( capitalizedLetters, capacity: 31 )
307
321
func isCapitalizedPrecomputed( _ c: Character ) -> Bool {
308
322
return capitalizedLettersPrecomputed. contains ( c. firstScalar. value)
309
323
}
@@ -345,7 +359,7 @@ let workload = """
345
359
346
360
@inline ( never)
347
361
public func run_CharacterPropertiesFetch( _ N: Int ) {
348
- for _ in 1 ... N*10 {
362
+ for _ in 1 ... N {
349
363
for c in workload {
350
364
blackHole ( isControl ( c) )
351
365
blackHole ( isAlphanumeric ( c) )
@@ -363,7 +377,7 @@ public func run_CharacterPropertiesFetch(_ N: Int) {
363
377
364
378
@inline ( never)
365
379
public func run_CharacterPropertiesStashed( _ N: Int ) {
366
- for _ in 1 ... N*10 {
380
+ for _ in 1 ... N {
367
381
for c in workload {
368
382
blackHole ( isControlStashed ( c) )
369
383
blackHole ( isAlphanumericStashed ( c) )
@@ -381,7 +395,7 @@ public func run_CharacterPropertiesStashed(_ N: Int) {
381
395
382
396
@inline ( never)
383
397
public func run_CharacterPropertiesStashedMemo( _ N: Int ) {
384
- for _ in 1 ... N*10 {
398
+ for _ in 1 ... N {
385
399
for c in workload {
386
400
blackHole ( isControlStashedMemo ( c) )
387
401
blackHole ( isAlphanumericStashedMemo ( c) )
@@ -399,7 +413,7 @@ public func run_CharacterPropertiesStashedMemo(_ N: Int) {
399
413
400
414
@inline ( never)
401
415
public func run_CharacterPropertiesPrecomputed( _ N: Int ) {
402
- for _ in 1 ... N*10 {
416
+ for _ in 1 ... N {
403
417
for c in workload {
404
418
blackHole ( isControlPrecomputed ( c) )
405
419
blackHole ( isAlphanumericPrecomputed ( c) )
0 commit comments