Skip to content

Commit a76fe7e

Browse files
authored
Merge pull request #950 from hsivonen/morebench
Add benches that use the main idna 1.0 entry point in idna and url
2 parents 6be49d0 + 9fd5e1c commit a76fe7e

File tree

2 files changed

+117
-1
lines changed

2 files changed

+117
-1
lines changed

idna/benches/all.rs

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,46 @@ fn to_ascii_merged(bench: &mut Bencher) {
4949
bench.iter(|| config.to_ascii(black_box(encoded)));
5050
}
5151

52+
fn to_ascii_cow_plain(bench: &mut Bencher) {
53+
let encoded = "example.com".as_bytes();
54+
bench.iter(|| idna::domain_to_ascii_cow(black_box(encoded), idna::AsciiDenyList::URL));
55+
}
56+
57+
fn to_ascii_cow_leading_digit(bench: &mut Bencher) {
58+
let encoded = "1test.example".as_bytes();
59+
bench.iter(|| idna::domain_to_ascii_cow(black_box(encoded), idna::AsciiDenyList::URL));
60+
}
61+
62+
fn to_ascii_cow_unicode_mixed(bench: &mut Bencher) {
63+
let encoded = "مثال.example".as_bytes();
64+
bench.iter(|| idna::domain_to_ascii_cow(black_box(encoded), idna::AsciiDenyList::URL));
65+
}
66+
67+
fn to_ascii_cow_punycode_mixed(bench: &mut Bencher) {
68+
let encoded = "xn--mgbh0fb.example".as_bytes();
69+
bench.iter(|| idna::domain_to_ascii_cow(black_box(encoded), idna::AsciiDenyList::URL));
70+
}
71+
72+
fn to_ascii_cow_unicode_ltr(bench: &mut Bencher) {
73+
let encoded = "නම.උදාහරණ".as_bytes();
74+
bench.iter(|| idna::domain_to_ascii_cow(black_box(encoded), idna::AsciiDenyList::URL));
75+
}
76+
77+
fn to_ascii_cow_punycode_ltr(bench: &mut Bencher) {
78+
let encoded = "xn--r0co.xn--ozc8dl2c3bxd".as_bytes();
79+
bench.iter(|| idna::domain_to_ascii_cow(black_box(encoded), idna::AsciiDenyList::URL));
80+
}
81+
82+
fn to_ascii_cow_unicode_rtl(bench: &mut Bencher) {
83+
let encoded = "الاسم.مثال".as_bytes();
84+
bench.iter(|| idna::domain_to_ascii_cow(black_box(encoded), idna::AsciiDenyList::URL));
85+
}
86+
87+
fn to_ascii_cow_punycode_rtl(bench: &mut Bencher) {
88+
let encoded = "xn--mgba0b1dh.xn--mgbh0fb".as_bytes();
89+
bench.iter(|| idna::domain_to_ascii_cow(black_box(encoded), idna::AsciiDenyList::URL));
90+
}
91+
5292
benchmark_group!(
5393
benches,
5494
to_unicode_puny_label,
@@ -58,5 +98,13 @@ benchmark_group!(
5898
to_ascii_already_puny_label,
5999
to_ascii_simple,
60100
to_ascii_merged,
101+
to_ascii_cow_plain,
102+
to_ascii_cow_leading_digit,
103+
to_ascii_cow_unicode_mixed,
104+
to_ascii_cow_punycode_mixed,
105+
to_ascii_cow_unicode_ltr,
106+
to_ascii_cow_punycode_ltr,
107+
to_ascii_cow_unicode_rtl,
108+
to_ascii_cow_punycode_rtl,
61109
);
62110
benchmark_main!(benches);

url/benches/parse_url.rs

Lines changed: 69 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,73 @@ fn long(bench: &mut Bencher) {
1919
bench.iter(|| black_box(url).parse::<Url>().unwrap());
2020
}
2121

22-
benchmark_group!(benches, short, long);
22+
fn plain(bench: &mut Bencher) {
23+
let url = "https://example.com/";
24+
25+
bench.bytes = url.len() as u64;
26+
bench.iter(|| black_box(url).parse::<Url>().unwrap());
27+
}
28+
29+
fn leading_digit(bench: &mut Bencher) {
30+
let url = "https://1test.example/";
31+
32+
bench.bytes = url.len() as u64;
33+
bench.iter(|| black_box(url).parse::<Url>().unwrap());
34+
}
35+
36+
fn unicode_mixed(bench: &mut Bencher) {
37+
let url = "https://مثال.example/";
38+
39+
bench.bytes = url.len() as u64;
40+
bench.iter(|| black_box(url).parse::<Url>().unwrap());
41+
}
42+
43+
fn punycode_mixed(bench: &mut Bencher) {
44+
let url = "https://xn--mgbh0fb.example/";
45+
46+
bench.bytes = url.len() as u64;
47+
bench.iter(|| black_box(url).parse::<Url>().unwrap());
48+
}
49+
50+
fn unicode_ltr(bench: &mut Bencher) {
51+
let url = "https://නම.උදාහරණ/";
52+
53+
bench.bytes = url.len() as u64;
54+
bench.iter(|| black_box(url).parse::<Url>().unwrap());
55+
}
56+
57+
fn punycode_ltr(bench: &mut Bencher) {
58+
let url = "https://xn--r0co.xn--ozc8dl2c3bxd/";
59+
60+
bench.bytes = url.len() as u64;
61+
bench.iter(|| black_box(url).parse::<Url>().unwrap());
62+
}
63+
64+
fn unicode_rtl(bench: &mut Bencher) {
65+
let url = "https://الاسم.مثال/";
66+
67+
bench.bytes = url.len() as u64;
68+
bench.iter(|| black_box(url).parse::<Url>().unwrap());
69+
}
70+
71+
fn punycode_rtl(bench: &mut Bencher) {
72+
let url = "https://xn--mgba0b1dh.xn--mgbh0fb/";
73+
74+
bench.bytes = url.len() as u64;
75+
bench.iter(|| black_box(url).parse::<Url>().unwrap());
76+
}
77+
78+
benchmark_group!(
79+
benches,
80+
short,
81+
long,
82+
plain,
83+
leading_digit,
84+
unicode_mixed,
85+
punycode_mixed,
86+
unicode_ltr,
87+
punycode_ltr,
88+
unicode_rtl,
89+
punycode_rtl,
90+
);
2391
benchmark_main!(benches);

0 commit comments

Comments
 (0)