Skip to content

Commit beb326e

Browse files
author
Itai Ferber
committed
Data hashing benchmarks
1 parent a457b0d commit beb326e

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

benchmark/single-source/DataBenchmarks.swift

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,13 @@ public let DataBenchmarks = [
171171
BenchmarkInfo(name: "StringToDataMedium",
172172
runFunction: { data($0*200, from: mediumString) }, tags: d,
173173
legacyFactor: 50),
174+
175+
BenchmarkInfo(name: "DataHashEmpty",
176+
runFunction: { hash($0*10_000, data: Data()) }, tags: d),
177+
BenchmarkInfo(name: "DataHashSmall",
178+
runFunction: { hash($0*10_000, data: small) }, tags: d),
179+
BenchmarkInfo(name: "DataHashMedium",
180+
runFunction: { hash($0*10_000, data: medium) }, tags: d),
174181
]
175182

176183
let emptyString = ""
@@ -383,3 +390,13 @@ public func data(_ N: Int, from string: String) {
383390
blackHole(Data(string.utf8))
384391
}
385392
}
393+
394+
@inline(never)
395+
public func hash(_ N: Int, data: Data) {
396+
var hasher = Hasher()
397+
for _ in 0 ..< N {
398+
hasher.combine(data)
399+
}
400+
401+
let _ = hasher.finalize()
402+
}

0 commit comments

Comments
 (0)