@@ -16,39 +16,26 @@ import TestsUtils
16
16
17
17
let t : [ BenchmarkCategory ] = [ . validation, . api, . Dictionary]
18
18
19
+ let size = 100
20
+ let numberMap = Dictionary ( uniqueKeysWithValues: zip ( 1 ... size, 1 ... size) )
21
+ let boxedNums = ( 1 ... size) . lazy. map { Box ( $0) }
22
+ let boxedNumMap = Dictionary ( uniqueKeysWithValues: zip ( boxedNums, boxedNums) )
23
+
19
24
public let DictionaryRemove = [
20
25
BenchmarkInfo ( name: " DictionaryRemove " ,
21
- runFunction: run_DictionaryRemove, tags: t, legacyFactor: 10 ) ,
26
+ runFunction: { for _ in 1 ... $0* 100 {
27
+ var dict = numberMap
28
+ for i in 1 ... size { dict. removeValue ( forKey: i) }
29
+ CheckResults ( dict. isEmpty)
30
+ } } , tags: t, legacyFactor: 10 ) ,
22
31
BenchmarkInfo ( name: " DictionaryRemoveOfObjects " ,
23
- runFunction: run_DictionaryRemoveOfObjects, tags: t, legacyFactor: 100 ) ,
32
+ runFunction: { for _ in 1 ... $0* 10 {
33
+ var dict = boxedNumMap
34
+ for i in 1 ... size { dict. removeValue ( forKey: Box ( i) ) }
35
+ CheckResults ( dict. isEmpty)
36
+ } } , tags: t, legacyFactor: 100 ) ,
24
37
]
25
38
26
- @inline ( never)
27
- public func run_DictionaryRemove( _ N: Int ) {
28
- let size = 100
29
- var dict = [ Int: Int] ( minimumCapacity: size)
30
-
31
- // Fill dictionary
32
- for i in 1 ... size {
33
- dict [ i] = i
34
- }
35
- CheckResults ( dict. count == size)
36
-
37
- var tmpDict = dict
38
- for _ in 1 ... 100 * N {
39
- tmpDict = dict
40
- // Empty dictionary
41
- for i in 1 ... size {
42
- tmpDict. removeValue ( forKey: i)
43
- }
44
- if !tmpDict. isEmpty {
45
- break
46
- }
47
- }
48
-
49
- CheckResults ( tmpDict. isEmpty)
50
- }
51
-
52
39
class Box < T : Hashable > : Hashable {
53
40
var value : T
54
41
@@ -64,29 +51,3 @@ class Box<T : Hashable> : Hashable {
64
51
return lhs. value == rhs. value
65
52
}
66
53
}
67
-
68
- @inline ( never)
69
- public func run_DictionaryRemoveOfObjects( _ N: Int ) {
70
- let size = 100
71
- var dict = Dictionary < Box < Int > , Box < Int > > ( minimumCapacity: size)
72
-
73
- // Fill dictionary
74
- for i in 1 ... size {
75
- dict [ Box ( i) ] = Box ( i)
76
- }
77
- CheckResults ( dict. count == size)
78
-
79
- var tmpDict = dict
80
- for _ in 1 ... 10 * N {
81
- tmpDict = dict
82
- // Empty dictionary
83
- for i in 1 ... size {
84
- tmpDict. removeValue ( forKey: Box ( i) )
85
- }
86
- if !tmpDict. isEmpty {
87
- break
88
- }
89
- }
90
-
91
- CheckResults ( tmpDict. isEmpty)
92
- }
0 commit comments