Skip to content

Commit 1ac4137

Browse files
committed
Add benchmarks.
1 parent 0afd988 commit 1ac4137

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

Benchmarks/Benchmarks/URL/BenchmarkURL.swift

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,4 +231,50 @@ let benchmarks = {
231231
}
232232
}
233233

234+
Benchmark("URL-Template-parsing") { benchmark in
235+
for _ in benchmark.scaledIterations {
236+
blackHole(URL.Template("/api/{version}/accounts/{accountId}/transactions/{transactionId}{?expand*,fields*,embed*,format}")!)
237+
blackHole(URL.Template("/special/{+a}/details")!)
238+
blackHole(URL.Template("/documents/{documentId}{#section,paragraph}")!)
239+
}
240+
}
241+
242+
let templates = [
243+
URL.Template("/var/{var}/who/{who}/x/{x}{?keys*,count*,list*,y}")!,
244+
URL.Template("/special/{+keys}/details")!,
245+
URL.Template("x/y/{#path:6}/here")!,
246+
URL.Template("a/b{/var,x}/here")!,
247+
URL.Template("a{?var,y}")!,
248+
]
249+
250+
var variables: [URL.Template.VariableName: URL.Template.Value] = [
251+
"count": ["one", "two", "three"],
252+
"dom": ["example", "com"],
253+
"dub": "me/too",
254+
"hello": "Hello World!",
255+
"half": "50%",
256+
"var": "value",
257+
"who": "fred",
258+
"base": "http://example.com/home/",
259+
"path": "/foo/bar",
260+
"list": ["red", "green", "blue"],
261+
"keys": [
262+
"semi": ";",
263+
"dot": ".",
264+
"comma": ",",
265+
],
266+
"v": "6",
267+
"x": "1024",
268+
"y": "768",
269+
"empty": "",
270+
"empty_keys": [:],
271+
]
272+
273+
Benchmark("URL-Template-expansion") { benchmark in
274+
for _ in benchmark.scaledIterations {
275+
for t in templates {
276+
blackHole(URL(template: t, variables: variables))
277+
}
278+
}
279+
}
234280
}

0 commit comments

Comments
 (0)