Skip to content

Commit a123b22

Browse files
committed
[benchmark] DictionaryRemove: Extract runFunctions
1 parent aa977ad commit a123b22

File tree

1 file changed

+18
-10
lines changed

1 file changed

+18
-10
lines changed

benchmark/single-source/DictionaryRemove.swift

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,9 @@ let boxedNumMap = Dictionary(uniqueKeysWithValues: zip(boxedNums, boxedNums))
2323

2424
public let DictionaryRemove = [
2525
BenchmarkInfo(name: "DictionaryRemove",
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),
26+
runFunction: remove, tags: t, legacyFactor: 10),
3127
BenchmarkInfo(name: "DictionaryRemoveOfObjects",
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),
28+
runFunction: removeObjects, tags: t, legacyFactor: 100),
3729
]
3830

3931
class Box<T : Hashable> : Hashable {
@@ -51,3 +43,19 @@ class Box<T : Hashable> : Hashable {
5143
return lhs.value == rhs.value
5244
}
5345
}
46+
47+
func remove(N: Int) {
48+
for _ in 1...100*N {
49+
var dict = numberMap
50+
for i in 1...size { dict.removeValue(forKey: i) }
51+
CheckResults(dict.isEmpty)
52+
}
53+
}
54+
55+
func removeObjects(N: Int) {
56+
for _ in 1...10*N {
57+
var dict = boxedNumMap
58+
for i in 1...size { dict.removeValue(forKey: Box(i)) }
59+
CheckResults(dict.isEmpty)
60+
}
61+
}

0 commit comments

Comments
 (0)