Skip to content

Commit 02c0494

Browse files
authored
(160218245) Improve URL component validation performance (#1509)
1 parent aa97b79 commit 02c0494

File tree

5 files changed

+186
-150
lines changed

5 files changed

+186
-150
lines changed

Benchmarks/Benchmarks/URL/BenchmarkURL.swift

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -32,38 +32,38 @@ let benchmarks = {
3232

3333
// MARK: - String Parsing
3434

35-
Benchmark("URL-ParseValidASCII") { benchmark in
35+
Benchmark("URL.ParseValidASCII") { benchmark in
3636
for _ in benchmark.scaledIterations {
3737
blackHole(URL(string: validURLString))
3838
}
3939
}
4040

41-
Benchmark("URLComponents-ParseValidASCII") { benchmark in
41+
Benchmark("URLComponents.ParseValidASCII") { benchmark in
4242
for _ in benchmark.scaledIterations {
4343
blackHole(URLComponents(string: validURLString))
4444
}
4545
}
4646

47-
Benchmark("URL-ParseInvalid") { benchmark in
47+
Benchmark("URL.ParseInvalid") { benchmark in
4848
for _ in benchmark.scaledIterations {
4949
blackHole(URL(string: invalidURLString))
5050
}
5151
}
5252

53-
Benchmark("URLComponents-ParseInvalid") { benchmark in
53+
Benchmark("URLComponents.ParseInvalid") { benchmark in
5454
for _ in benchmark.scaledIterations {
5555
blackHole(URLComponents(string: invalidURLString))
5656
}
5757
}
5858

5959
#if os(macOS) || compiler(>=6)
60-
Benchmark("URL-ParseAndEncode") { benchmark in
60+
Benchmark("URL.ParseAndEncode") { benchmark in
6161
for _ in benchmark.scaledIterations {
6262
blackHole(URL(string: encodableURLString))
6363
}
6464
}
6565

66-
Benchmark("URLComponents-ParseAndEncode") { benchmark in
66+
Benchmark("URLComponents.ParseAndEncode") { benchmark in
6767
for _ in benchmark.scaledIterations {
6868
blackHole(URLComponents(string: encodableURLString))
6969
}
@@ -87,7 +87,7 @@ let benchmarks = {
8787

8888
#if os(macOS) || compiler(>=6)
8989
// Component functions, e.g. path(), are available in macOS 13 and Swift 6
90-
Benchmark("URL-GetEncodedComponents") { benchmark in
90+
Benchmark("URL.GetEncodedComponents") { benchmark in
9191
for _ in benchmark.scaledIterations {
9292
blackHole(encodedURL.scheme)
9393
blackHole(encodedURL.user())
@@ -100,7 +100,7 @@ let benchmarks = {
100100
}
101101
#endif
102102

103-
Benchmark("URLComponents-GetEncodedComponents") { benchmark in
103+
Benchmark("URLComponents.GetEncodedComponents") { benchmark in
104104
for _ in benchmark.scaledIterations {
105105
blackHole(encodedComp.scheme)
106106
blackHole(encodedComp.percentEncodedUser)
@@ -116,7 +116,7 @@ let benchmarks = {
116116
}
117117
}
118118

119-
Benchmark("URL-GetDecodedComponents") { benchmark in
119+
Benchmark("URL.GetDecodedComponents") { benchmark in
120120
for _ in benchmark.scaledIterations {
121121
blackHole(encodedURL.scheme)
122122
blackHole(encodedURL.user)
@@ -128,7 +128,7 @@ let benchmarks = {
128128
}
129129
}
130130

131-
Benchmark("URLComponents-GetDecodedComponents") { benchmark in
131+
Benchmark("URLComponents.GetDecodedComponents") { benchmark in
132132
for _ in benchmark.scaledIterations {
133133
blackHole(encodedComp.scheme)
134134
blackHole(encodedComp.user)
@@ -141,7 +141,7 @@ let benchmarks = {
141141
}
142142

143143
let validComp = URLComponents(string: validURLString)!
144-
Benchmark("URLComponents-GetComponentRanges") { benchmark in
144+
Benchmark("URLComponents.GetComponentRanges") { benchmark in
145145
for _ in benchmark.scaledIterations {
146146
blackHole(validComp.rangeOfScheme)
147147
blackHole(validComp.rangeOfUser)
@@ -156,7 +156,7 @@ let benchmarks = {
156156

157157
// MARK: - Set URL Components
158158

159-
Benchmark("URLComponents-SetComponents") { benchmark in
159+
Benchmark("URLComponents.SetComponents") { benchmark in
160160
for _ in benchmark.scaledIterations {
161161
var comp = URLComponents()
162162
comp.scheme = "scheme"
@@ -171,7 +171,7 @@ let benchmarks = {
171171
}
172172
}
173173

174-
Benchmark("URLComponents-SetEncodableComponents") { benchmark in
174+
Benchmark("URLComponents.SetEncodableComponents") { benchmark in
175175
for _ in benchmark.scaledIterations {
176176
var comp = URLComponents()
177177
comp.scheme = "scheme"
@@ -200,15 +200,15 @@ let benchmarks = {
200200
URLQueryItem(name: "name with no value", value: nil)
201201
]
202202

203-
Benchmark("URLComponents-SetQueryItems") { benchmark in
203+
Benchmark("URLComponents.SetQueryItems") { benchmark in
204204
for _ in benchmark.scaledIterations {
205205
var comp = URLComponents()
206206
comp.queryItems = validQueryItems
207207
blackHole(comp)
208208
}
209209
}
210210

211-
Benchmark("URLComponents-SetEncodableQueryItems") { benchmark in
211+
Benchmark("URLComponents.SetEncodableQueryItems") { benchmark in
212212
for _ in benchmark.scaledIterations {
213213
var comp = URLComponents()
214214
comp.queryItems = encodableQueryItems
@@ -219,19 +219,21 @@ let benchmarks = {
219219
var queryComp = URLComponents()
220220
queryComp.queryItems = encodableQueryItems
221221

222-
Benchmark("URLComponents-GetEncodedQueryItems") { benchmark in
222+
Benchmark("URLComponents.GetEncodedQueryItems") { benchmark in
223223
for _ in benchmark.scaledIterations {
224224
blackHole(queryComp.percentEncodedQueryItems)
225225
}
226226
}
227227

228-
Benchmark("URLComponents-GetDecodedQueryItems") { benchmark in
228+
Benchmark("URLComponents.GetDecodedQueryItems") { benchmark in
229229
for _ in benchmark.scaledIterations {
230230
blackHole(queryComp.queryItems)
231231
}
232232
}
233233

234-
Benchmark("URL-Template-parsing") { benchmark in
234+
// MARK: - URL.Template
235+
236+
Benchmark("URL.TemplateParsing") { benchmark in
235237
for _ in benchmark.scaledIterations {
236238
blackHole(URL.Template("/api/{version}/accounts/{accountId}/transactions/{transactionId}{?expand*,fields*,embed*,format}")!)
237239
blackHole(URL.Template("/special/{+a}/details")!)
@@ -270,7 +272,7 @@ let benchmarks = {
270272
.init("empty_keys"): [:],
271273
]
272274

273-
Benchmark("URL-Template-expansion") { benchmark in
275+
Benchmark("URL.TemplateExpansion") { benchmark in
274276
for _ in benchmark.scaledIterations {
275277
for t in templates {
276278
blackHole(URL(template: t, variables: variables))

0 commit comments

Comments
 (0)