@@ -231,4 +231,48 @@ 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+ Benchmark ( " URL Template expansion " ) { benchmark in
243+ let templates = [
244+ URL . Template ( " /var/{var}/who/{who}/x/{x}{?keys*,count*,list*,y} " ) !,
245+ URL . Template ( " /special/{+keys}/details " ) !,
246+ URL . Template ( " x/y/{#path:6}/here " ) !,
247+ URL . Template ( " a/b{/var,x}/here " ) !,
248+ URL . Template ( " a{?var,y} " ) !,
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+ for _ in benchmark. scaledIterations {
273+ for t in templates {
274+ blackHole ( URL ( template: t, variables: variables) )
275+ }
276+ }
277+ }
234278}
0 commit comments