Skip to content

[Benchmark] Benchmark UTF8 decoding from typed & untyped bufferys #22277

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

Closed
wants to merge 1 commit into from
Closed
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
57 changes: 55 additions & 2 deletions benchmark/single-source/UTF8Decode.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,22 @@ public let UTF8Decode = [
name: "UTF8Decode_InitFromBytes",
runFunction: run_UTF8Decode_InitFromBytes,
tags: [.validation, .api, .String]),
BenchmarkInfo(
name: "UTF8Decode_InitDecoding_buffer",
runFunction: run_UTF8Decode_InitDecoding_buffer,
tags: [.validation, .api, .String]),
BenchmarkInfo(
name: "UTF8Decode_InitFromBytes_buffer",
runFunction: run_UTF8Decode_InitFromBytes_buffer,
tags: [.validation, .api, .String]),
BenchmarkInfo(
name: "UTF8Decode_InitDecoding_rawbuffer",
runFunction: run_UTF8Decode_InitDecoding_rawbuffer,
tags: [.validation, .api, .String]),
BenchmarkInfo(
name: "UTF8Decode_InitFromBytes_rawbuffer",
runFunction: run_UTF8Decode_InitFromBytes_rawbuffer,
tags: [.validation, .api, .String]),
BenchmarkInfo(
name: "UTF8Decode_InitFromData_ascii",
runFunction: run_UTF8Decode_InitFromData_ascii,
Expand Down Expand Up @@ -92,6 +108,7 @@ public func run_UTF8Decode_InitFromData(_ N: Int) {
blackHole(String(data: input, encoding: .utf8))
}
}
// Array<UInt8>.
@inline(never)
public func run_UTF8Decode_InitDecoding(_ N: Int) {
let input = allStringsBytes
Expand All @@ -106,6 +123,44 @@ public func run_UTF8Decode_InitFromBytes(_ N: Int) {
blackHole(String(bytes: input, encoding: .utf8))
}
}
// UnsafeBufferPointer<UInt8>.
@inline(never)
public func run_UTF8Decode_InitDecoding_buffer(_ N: Int) {
let input = allStringsBytes
for _ in 0..<200*N {
input.withUnsafeBufferPointer {
blackHole(String(decoding: $0, as: UTF8.self))
}
}
}
@inline(never)
public func run_UTF8Decode_InitFromBytes_buffer(_ N: Int) {
let input = allStringsBytes
for _ in 0..<200*N {
input.withUnsafeBufferPointer {
blackHole(String(bytes: $0, encoding: .utf8))
}
}
}
// UnsafeRawBufferPointer.
@inline(never)
public func run_UTF8Decode_InitDecoding_rawbuffer(_ N: Int) {
let input = allStringsBytes
for _ in 0..<200*N {
input.withUnsafeBytes {
blackHole(String(decoding: $0, as: UTF8.self))
}
}
}
@inline(never)
public func run_UTF8Decode_InitFromBytes_rawbuffer(_ N: Int) {
let input = allStringsBytes
for _ in 0..<200*N {
input.withUnsafeBytes {
blackHole(String(bytes: $0, encoding: .utf8))
}
}
}

@inline(never)
public func run_UTF8Decode_InitFromData_ascii(_ N: Int) {
Expand All @@ -128,5 +183,3 @@ public func run_UTF8Decode_InitFromBytes_ascii(_ N: Int) {
blackHole(String(bytes: input, encoding: .utf8))
}
}