Skip to content

[benchmark] Add dataUsingUTF8Encoding() #22648

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Feb 20, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 21 additions & 5 deletions benchmark/single-source/DataBenchmarks.swift
Original file line number Diff line number Diff line change
Expand Up @@ -169,18 +169,27 @@ public let DataBenchmarks = [
legacyFactor: 50),

BenchmarkInfo(name: "StringToDataEmpty",
runFunction: { data($0*200, from: emptyString) }, tags: d,
runFunction: { dataFromUTF8View($0*200, from: emptyString) }, tags: d,
legacyFactor: 50),
BenchmarkInfo(name: "StringToDataSmall",
runFunction: { data($0*200, from: smallString) }, tags: d,
runFunction: { dataFromUTF8View($0*200, from: smallString) }, tags: d,
legacyFactor: 50),
BenchmarkInfo(name: "StringToDataMedium",
runFunction: { data($0*200, from: mediumString) }, tags: d,
runFunction: { dataFromUTF8View($0*200, from: mediumString) }, tags: d,
legacyFactor: 50),
BenchmarkInfo(name: "StringToDataLargeUnicode",
runFunction: { data($0*200, from: largeUnicodeString) }, tags: d,
runFunction: { dataFromUTF8View($0*200, from: largeUnicodeString) }, tags: d,
legacyFactor: 50),

BenchmarkInfo(name: "String.data.Empty",
runFunction: { dataUsingUTF8Encoding($0*200, from: emptyString) }, tags: d),
BenchmarkInfo(name: "String.data.Small",
runFunction: { dataUsingUTF8Encoding($0*200, from: smallString) }, tags: d),
BenchmarkInfo(name: "String.data.Medium",
runFunction: { dataUsingUTF8Encoding($0*200, from: mediumString) }, tags: d),
BenchmarkInfo(name: "String.data.LargeUnicode",
runFunction: { dataUsingUTF8Encoding($0*200, from: largeUnicodeString) }, tags: d),

BenchmarkInfo(name: "Data.hash.Empty",
runFunction: { hash($0*10_000, data: Data()) }, tags: d),
BenchmarkInfo(name: "Data.hash.Small",
Expand Down Expand Up @@ -397,12 +406,19 @@ public func string(_ N: Int, from data: Data) {
}

@inline(never)
public func data(_ N: Int, from string: String) {
public func dataFromUTF8View(_ N: Int, from string: String) {
for _ in 1...N {
blackHole(Data(string.utf8))
}
}

@inline(never)
public func dataUsingUTF8Encoding(_ N: Int, from string: String) {
for _ in 1...N {
autoreleasepool { blackHole(string.data(using: .utf8)) }
}
}

@inline(never)
public func hash(_ N: Int, data: Data) {
var hasher = Hasher()
Expand Down