@@ -13,77 +13,44 @@ import CollectionsBenchmark
1313
1414extension Benchmark {
1515 public mutating func addSortedDictionaryBenchmarks( ) {
16- // self.add(
17- // title: "SortedDictionary<Int, Int> init(uniqueKeysWithValues:)",
18- // input: [Int].self
19- // ) { input in
20- // let keysAndValues = input.lazy.map { (key: $0, value: 2 * $0) }
21- //
22- // return { timer in
23- // blackHole(SortedDictionary(uniqueKeysWithValues: keysAndValues))
24- // }
25- // }
26- //
27- // self.add(
28- // title: "SortedDictionary<Int, Int> subscript, append",
29- // input: [Int].self
30- // ) { input in
31- // let keysAndValues = input.lazy.map { (key: $0, value: 2 * $0) }
32- // var sortedDictionary = SortedDictionary<Int, Int>()
33- //
34- // return { timer in
35- // for (key, value) in keysAndValues {
36- // sortedDictionary[key] = value
37- // }
38- // blackHole(sortedDictionary)
39- // }
40- // }
41-
4216 self . add (
43- title: " SortedDictionary<Int, Int> subscript, successful lookups " ,
17+ title: " SortedDictionary<Int, Int> init(uniqueKeysWithValues:) " ,
4418 input: [ Int ] . self
4519 ) { input in
4620 let keysAndValues = input. lazy. map { ( key: $0, value: 2 * $0) }
47- let sortedDictionary = SortedDictionary < Int , Int > ( uniqueKeysWithValues: keysAndValues)
48-
21+
22+ return { timer in
23+ blackHole ( SortedDictionary ( uniqueKeysWithValues: keysAndValues) )
24+ }
25+ }
26+
27+ self . add (
28+ title: " SortedDictionary<Int, Int> subscript, append " ,
29+ input: [ Int ] . self
30+ ) { input in
31+ let keysAndValues = input. lazy. map { ( key: $0, value: 2 * $0) }
32+ var sortedDictionary = SortedDictionary < Int , Int > ( )
33+
4934 return { timer in
5035 for (key, value) in keysAndValues {
51- precondition ( sortedDictionary [ key] == value)
36+ sortedDictionary [ key] = value
5237 }
38+ blackHole ( sortedDictionary)
5339 }
5440 }
5541
56- // self.add(
57- // title: "SortedDictionary<Int, Int>._BTree firstValue",
58- // input: [Int].self
59- // ) { input in
60- // let keysAndValues = input.lazy.map { (key: $0, value: 2 * $0) }
61- // var tree = _BTree<Int, Int>()
62- //
63- // for (key, value) in keysAndValues {
64- // tree.insertOrUpdate((key, value))
65- // }
66- //
67- // return { timer in
68- // for (key, value) in keysAndValues {
69- // precondition(tree.anyValue(for: key) != nil)
70- // }
71- // }
72- // }
73-
74- // self.add(
75- // title: "SortedDictionary<Int, Int>._BTree insertOrUpdate(element:)",
76- // input: [Int].self
77- // ) { input in
78- // let keysAndValues = input.lazy.map { (key: $0, value: 2 * $0) }
79- //
80- // return { timer in
81- // var tree = _BTree<Int, Int>()
82- // for (key, value) in keysAndValues {
83- // tree.insertOrUpdate((key, value))
84- // }
85- // blackHole(tree)
86- // }
87- // }
42+ self . add (
43+ title: " SortedDictionary<Int, Int> subscript, successful lookups " ,
44+ input: ( [ Int] , [ Int] ) . self
45+ ) { input, lookups in
46+ let keysAndValues = input. lazy. map { ( key: $0, value: 2 * $0) }
47+ let sortedDictionary = SortedDictionary < Int , Int > ( uniqueKeysWithValues: keysAndValues)
48+
49+ return { timer in
50+ for key in lookups {
51+ precondition ( sortedDictionary. _root. contains ( key: key) )
52+ }
53+ }
54+ }
8855 }
8956}
0 commit comments