13
13
import TestsUtils
14
14
15
15
public let DictionaryGroup = [
16
- BenchmarkInfo ( name: " DictionaryGroup " , runFunction: run_DictionaryGroup, tags: [ . validation, . api, . Dictionary] ) ,
17
- BenchmarkInfo ( name: " DictionaryGroupOfObjects " , runFunction: run_DictionaryGroupOfObjects, tags: [ . validation, . api, . Dictionary] ,
16
+ BenchmarkInfo ( name: " DictionaryGroup " ,
17
+ runFunction: run_DictionaryGroup,
18
+ tags: [ . validation, . api, . Dictionary] ) ,
19
+ BenchmarkInfo ( name: " DictionaryGroupOfObjects " ,
20
+ runFunction: run_DictionaryGroupOfObjects,
21
+ tags: [ . validation, . api, . Dictionary] ,
18
22
setUpFunction: { blackHole ( inputObjects) } ,
19
- tearDownFunction: { inputObjects = nil } ) ,
23
+ tearDownFunction: { inputObjects = nil } ,
24
+ legacyFactor: 9
25
+ ) ,
20
26
]
21
27
22
- let count = 10_000
23
- let result = count / 10
24
-
25
28
@inline ( never)
26
29
public func run_DictionaryGroup( _ N: Int ) {
27
30
for _ in 1 ... N {
28
- let dict = Dictionary ( grouping: 0 ..< count , by: { $0 % 10 } )
31
+ let dict = Dictionary ( grouping: 0 ..< 10_000 , by: { $0 % 10 } )
29
32
CheckResults ( dict. count == 10 )
30
- CheckResults ( dict [ 0 ] !. count == result )
33
+ CheckResults ( dict [ 0 ] !. count == 1_000 )
31
34
}
32
35
}
33
36
@@ -47,14 +50,14 @@ class Box<T : Hashable> : Hashable {
47
50
}
48
51
}
49
52
50
- var inputObjects : [ Box < Int > ] ! = ( 0 ..< count ) . map { Box ( $0) }
53
+ var inputObjects : [ Box < Int > ] ! = ( 0 ..< 1_000 ) . lazy . map { Box ( $0) }
51
54
52
55
@inline ( never)
53
56
public func run_DictionaryGroupOfObjects( _ N: Int ) {
54
57
let objects : [ Box < Int > ] = inputObjects
55
58
for _ in 1 ... N {
56
59
let dict = Dictionary ( grouping: objects, by: { Box ( $0. value % 10 ) } )
57
60
CheckResults ( dict. count == 10 )
58
- CheckResults ( dict [ Box ( 0 ) ] !. count == result )
61
+ CheckResults ( dict [ Box ( 0 ) ] !. count == 100 )
59
62
}
60
63
}
0 commit comments