-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Add benchmarks for creating Strings from ASCII #27665
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,6 +42,18 @@ public let UTF8Decode = [ | |
name: "UTF8Decode_InitFromBytes_ascii", | ||
runFunction: run_UTF8Decode_InitFromBytes_ascii, | ||
tags: [.validation, .api, .String]), | ||
BenchmarkInfo( | ||
name: "UTF8Decode_InitFromData_ascii_as_ascii", | ||
runFunction: run_UTF8Decode_InitFromData_ascii_as_ascii, | ||
tags: [.validation, .api, .String]), | ||
BenchmarkInfo( | ||
name: "UTF8Decode_InitDecoding_ascii_as_ascii", | ||
runFunction: run_UTF8Decode_InitDecoding_ascii_as_ascii, | ||
tags: [.validation, .api, .String]), | ||
BenchmarkInfo( | ||
name: "UTF8Decode_InitFromBytes_ascii_as_ascii", | ||
runFunction: run_UTF8Decode_InitFromBytes_ascii_as_ascii, | ||
tags: [.validation, .api, .String]), | ||
] | ||
|
||
// 1-byte sequences | ||
|
@@ -129,4 +141,26 @@ public func run_UTF8Decode_InitFromBytes_ascii(_ N: Int) { | |
} | ||
} | ||
|
||
@inline(never) | ||
public func run_UTF8Decode_InitFromData_ascii_as_ascii(_ N: Int) { | ||
let input = asciiData | ||
for _ in 0..<1_000*N { | ||
blackHole(String(data: input, encoding: .ascii)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
It may be worth passing |
||
} | ||
} | ||
@inline(never) | ||
public func run_UTF8Decode_InitDecoding_ascii_as_ascii(_ N: Int) { | ||
let input = asciiBytes | ||
for _ in 0..<1_000*N { | ||
blackHole(String(decoding: input, as: Unicode.ASCII.self)) | ||
} | ||
} | ||
@inline(never) | ||
public func run_UTF8Decode_InitFromBytes_ascii_as_ascii(_ N: Int) { | ||
let input = asciiBytes | ||
for _ in 0..<1_000*N { | ||
blackHole(String(bytes: input, encoding: .ascii)) | ||
} | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, the names aren't great here. Shouldn't we call this
ASCIIDecode.initFromData
?The existing benchmarks have set an unfortunate pattern, but perhaps it's worth breaking it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I felt keeping the prefix the same was worthwhile for being able to do something like "run all the benchmarks for X". The name does really suck though.