@@ -18,6 +18,18 @@ public let UTF8Decode = [
18
18
name: " UTF8Decode " ,
19
19
runFunction: run_UTF8Decode,
20
20
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] ) ,
21
33
BenchmarkInfo (
22
34
name: " UTF8Decode_InitFromData_ascii " ,
23
35
runFunction: run_UTF8Decode_InitFromData_ascii,
@@ -47,6 +59,9 @@ let japanese = "日本語(にほんご、にっぽんご)は、主に日本
47
59
let emoji = " Panda 🐼, Dog 🐶, Cat 🐱, Mouse 🐭. "
48
60
49
61
let allStrings = [ ascii, russian, japanese, emoji] . map { Array ( $0. utf8) }
62
+ let allStringsBytes : [ UInt8 ] = Array ( allStrings. joined ( ) )
63
+ let allStringsData : Data = Data ( allStringsBytes)
64
+
50
65
51
66
@inline ( never)
52
67
public func run_UTF8Decode( _ N: Int ) {
@@ -70,6 +85,28 @@ public func run_UTF8Decode(_ N: Int) {
70
85
}
71
86
}
72
87
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
+
73
110
@inline ( never)
74
111
public func run_UTF8Decode_InitFromData_ascii( _ N: Int ) {
75
112
let input = asciiData
0 commit comments