Skip to content

Commit d21d2e6

Browse files
authored
Add URL construction benchmark (Azure#3190)
1 parent d874a4f commit d21d2e6

File tree

1 file changed

+42
-1
lines changed

1 file changed

+42
-1
lines changed

sdk/core/azure_core/benches/benchmarks.rs

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
14
use azure_core::http::{
25
headers::Headers, BufResponse, HttpClient, Method, Request, StatusCode, Url,
36
};
@@ -25,6 +28,44 @@ fn url_parsing_benchmark(c: &mut Criterion) {
2528
}
2629
}
2730

31+
const ENDPOINT: &str = "https://my-vault.vault.azure.net";
32+
33+
fn url_construction(c: &mut Criterion) {
34+
let endpoint: Url = ENDPOINT.parse().unwrap();
35+
let api_version = "7.6";
36+
37+
let mut group = c.benchmark_group("url_construction");
38+
39+
group.bench_function("append", |b| {
40+
b.iter(|| {
41+
let mut url = endpoint
42+
.clone()
43+
.join("secrets/")
44+
.unwrap()
45+
.join("secret-name")
46+
.unwrap()
47+
.join("secret-version")
48+
.unwrap();
49+
url.query_pairs_mut()
50+
.append_pair("api-version", api_version);
51+
let _ = black_box(url);
52+
})
53+
});
54+
55+
group.bench_function("format", |b| {
56+
b.iter(|| {
57+
let mut url = endpoint.clone();
58+
let mut path = String::from("secrets/{secret-name}/{secret-version}");
59+
path = path.replace("{secret-name}", "secret-name");
60+
path = path.replace("{secret-version}", "secret-version");
61+
url = url.join(&path).unwrap();
62+
url.query_pairs_mut()
63+
.append_pair("api-version", api_version);
64+
let _ = black_box(url);
65+
})
66+
});
67+
}
68+
2869
fn http_transport_test(c: &mut Criterion) {
2970
let rt = tokio::runtime::Runtime::new().unwrap();
3071

@@ -65,7 +106,7 @@ fn http_transport_test(c: &mut Criterion) {
65106
criterion_group! {
66107
name = benchmarks;
67108
config = Criterion::default();
68-
targets = url_parsing_benchmark, http_transport_test
109+
targets = url_parsing_benchmark, url_construction, http_transport_test
69110
}
70111

71112
criterion_main!(benchmarks);

0 commit comments

Comments
 (0)