mirror of
https://github.com/apple/swift-collections
synced 2026-11-28 05:04:21 +00:00
[PersistentDictionary] Add index striding benchmark
This commit is contained in:
1 parent
8c9ae08abf
commit
9407eff8ca
1 file changed
+19
@@ -72,6 +72,25 @@ extension Benchmark {
|
||||
}
|
||||
}
|
||||
|
||||
self.add(
|
||||
title: "PersistentDictionary<Int, Int> striding, 10 steps",
|
||||
input: [Int].self
|
||||
) { input in
|
||||
let d = PersistentDictionary(
|
||||
uniqueKeysWithValues: input.lazy.map { ($0, 2 * $0) })
|
||||
let steps = stride(from: 0, through: 10 * d.count, by: d.count)
|
||||
.map { $0 / 10 }
|
||||
return { timer in
|
||||
var i = d.startIndex
|
||||
for j in 1 ..< steps.count {
|
||||
let distance = steps[j] - steps[j - 1]
|
||||
i = identity(d.index(i, offsetBy: distance))
|
||||
}
|
||||
precondition(i == d.endIndex)
|
||||
blackHole(i)
|
||||
}
|
||||
}
|
||||
|
||||
self.add(
|
||||
title: "PersistentDictionary<Int, Int> indexing subscript",
|
||||
input: ([Int], [Int]).self
|
||||
|
||||
Reference in new issue
Block a user