Skip to content
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

Data Inlinability Refinements #21754

Merged
merged 15 commits into from
Jan 14, 2019
Merged
Show file tree
Hide file tree
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
47 changes: 46 additions & 1 deletion benchmark/single-source/DataBenchmarks.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ public let DataBenchmarks = [
0, 1, 2, 3, 4, 5, 6,
])) } }, tags: d, legacyFactor: 20),

BenchmarkInfo(name: "Data.init.Sequence.ExactCount", runFunction: {
for _ in 0..<$0*100 {
blackHole(Data(repeatElement(UInt8(0xA0), count: 809)))
} }, tags: d),
BenchmarkInfo(name: "Data.init.Sequence.UnderestimatedCount", runFunction: {
for _ in 0..<$0*100 { blackHole(Data(repeatElementSeq(809))) } }, tags: d),

BenchmarkInfo(name: "DataSubscriptSmall",
runFunction: { let data = small
for _ in 0..<$0*10_000 { blackHole(data[1]) } }, tags: d),
Expand Down Expand Up @@ -112,7 +119,13 @@ public let DataBenchmarks = [

BenchmarkInfo(name: "DataAppendSequence",
runFunction: { append($0*100, sequenceLength: 809, to: medium) },
tags: d, legacyFactor: 100),
tags: d, legacyFactor: 100),
BenchmarkInfo(name: "Data.append.Sequence.ExactCount", runFunction: {
append($0*100, sequence: repeatElement(UInt8(0xA0), count: 809),
to: medium) }, tags: d),
BenchmarkInfo(name: "Data.append.Sequence.UnderestimatedCount", runFunction: {
append($0*100, sequence: repeatElementSeq(809), to: medium) },
tags: d),

BenchmarkInfo(name: "DataAppendDataSmallToSmall",
runFunction: { append($0*500, data: small, to: small) }, tags: d,
Expand Down Expand Up @@ -161,6 +174,13 @@ public let DataBenchmarks = [
BenchmarkInfo(name: "StringToDataMedium",
runFunction: { data($0*200, from: mediumString) }, tags: d,
legacyFactor: 50),

BenchmarkInfo(name: "Data.hash.Empty",
runFunction: { hash($0*10_000, data: Data()) }, tags: d),
BenchmarkInfo(name: "Data.hash.Small",
runFunction: { hash($0*10_000, data: small) }, tags: d),
BenchmarkInfo(name: "Data.hash.Medium",
runFunction: { hash($0*1_000, data: medium) }, tags: d),
]

let emptyString = ""
Expand All @@ -174,6 +194,12 @@ let small = sampleData(.small)
let medium = sampleData(.medium)
let large = sampleData(.large)

let repeatElementSeq = { count in
return sequence(state: count) { (i: inout Int) -> UInt8? in
defer { i = i &- 1 }; return i > 0 ? UInt8(0xA0) : nil
}
}

enum SampleKind {
case small
case medium
Expand Down Expand Up @@ -280,6 +306,15 @@ func append(_ N: Int, sequenceLength: Int, to data: Data) {
}
}

@inline(never)
func append<S: Sequence>(_ N: Int, sequence: S, to data: Data)
where S.Element == UInt8 {
for _ in 1...N {
var copy = data
copy.append(contentsOf: sequence)
}
}

@inline(never)
func resetBytes(_ N: Int, in range: Range<Data.Index>, data: Data) {
for _ in 1...N {
Expand Down Expand Up @@ -358,3 +393,13 @@ public func data(_ N: Int, from string: String) {
blackHole(Data(string.utf8))
}
}

@inline(never)
public func hash(_ N: Int, data: Data) {
var hasher = Hasher()
for _ in 0 ..< N {
hasher.combine(data)
}

let _ = hasher.finalize()
}
Loading