Skip to content

Commit 15e869b

Browse files
committed
[benchmark] Non-ASCII variants of UTF-8 decoding inits
1 parent 763fc06 commit 15e869b

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

benchmark/single-source/UTF8Decode.swift

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,18 @@ public let UTF8Decode = [
1818
name: "UTF8Decode",
1919
runFunction: run_UTF8Decode,
2020
tags: [.validation, .api, .String]),
21+
BenchmarkInfo(
22+
name: "UTF8Decode_InitFromData",
23+
runFunction: run_UTF8Decode_InitFromData,
24+
tags: [.validation, .api, .String]),
25+
BenchmarkInfo(
26+
name: "UTF8Decode_InitDecoding",
27+
runFunction: run_UTF8Decode_InitDecoding,
28+
tags: [.validation, .api, .String]),
29+
BenchmarkInfo(
30+
name: "UTF8Decode_InitFromBytes",
31+
runFunction: run_UTF8Decode_InitFromBytes,
32+
tags: [.validation, .api, .String]),
2133
BenchmarkInfo(
2234
name: "UTF8Decode_InitFromData_ascii",
2335
runFunction: run_UTF8Decode_InitFromData_ascii,
@@ -47,6 +59,9 @@ let japanese = "日本語(にほんご、にっぽんご)は、主に日本
4759
let emoji = "Panda 🐼, Dog 🐶, Cat 🐱, Mouse 🐭."
4860

4961
let allStrings = [ascii, russian, japanese, emoji].map { Array($0.utf8) }
62+
let allStringsBytes: [UInt8] = Array(allStrings.joined())
63+
let allStringsData: Data = Data(allStringsBytes)
64+
5065

5166
@inline(never)
5267
public func run_UTF8Decode(_ N: Int) {
@@ -70,6 +85,28 @@ public func run_UTF8Decode(_ N: Int) {
7085
}
7186
}
7287

88+
@inline(never)
89+
public func run_UTF8Decode_InitFromData(_ N: Int) {
90+
let input = allStringsData
91+
for _ in 0..<200*N {
92+
blackHole(String(data: input, encoding: .utf8))
93+
}
94+
}
95+
@inline(never)
96+
public func run_UTF8Decode_InitDecoding(_ N: Int) {
97+
let input = allStringsBytes
98+
for _ in 0..<200*N {
99+
blackHole(String(decoding: input, as: UTF8.self))
100+
}
101+
}
102+
@inline(never)
103+
public func run_UTF8Decode_InitFromBytes(_ N: Int) {
104+
let input = allStringsBytes
105+
for _ in 0..<200*N {
106+
blackHole(String(bytes: input, encoding: .utf8))
107+
}
108+
}
109+
73110
@inline(never)
74111
public func run_UTF8Decode_InitFromData_ascii(_ N: Int) {
75112
let input = asciiData

0 commit comments

Comments
 (0)