diff --git a/idna/benches/all.rs b/idna/benches/all.rs index c59c42335..e39e5bd2f 100644 --- a/idna/benches/all.rs +++ b/idna/benches/all.rs @@ -49,6 +49,46 @@ fn to_ascii_merged(bench: &mut Bencher) { bench.iter(|| config.to_ascii(black_box(encoded))); } +fn to_ascii_cow_plain(bench: &mut Bencher) { + let encoded = "example.com".as_bytes(); + bench.iter(|| idna::domain_to_ascii_cow(black_box(encoded), idna::AsciiDenyList::URL)); +} + +fn to_ascii_cow_leading_digit(bench: &mut Bencher) { + let encoded = "1test.example".as_bytes(); + bench.iter(|| idna::domain_to_ascii_cow(black_box(encoded), idna::AsciiDenyList::URL)); +} + +fn to_ascii_cow_unicode_mixed(bench: &mut Bencher) { + let encoded = "مثال.example".as_bytes(); + bench.iter(|| idna::domain_to_ascii_cow(black_box(encoded), idna::AsciiDenyList::URL)); +} + +fn to_ascii_cow_punycode_mixed(bench: &mut Bencher) { + let encoded = "xn--mgbh0fb.example".as_bytes(); + bench.iter(|| idna::domain_to_ascii_cow(black_box(encoded), idna::AsciiDenyList::URL)); +} + +fn to_ascii_cow_unicode_ltr(bench: &mut Bencher) { + let encoded = "නම.උදාහරණ".as_bytes(); + bench.iter(|| idna::domain_to_ascii_cow(black_box(encoded), idna::AsciiDenyList::URL)); +} + +fn to_ascii_cow_punycode_ltr(bench: &mut Bencher) { + let encoded = "xn--r0co.xn--ozc8dl2c3bxd".as_bytes(); + bench.iter(|| idna::domain_to_ascii_cow(black_box(encoded), idna::AsciiDenyList::URL)); +} + +fn to_ascii_cow_unicode_rtl(bench: &mut Bencher) { + let encoded = "الاسم.مثال".as_bytes(); + bench.iter(|| idna::domain_to_ascii_cow(black_box(encoded), idna::AsciiDenyList::URL)); +} + +fn to_ascii_cow_punycode_rtl(bench: &mut Bencher) { + let encoded = "xn--mgba0b1dh.xn--mgbh0fb".as_bytes(); + bench.iter(|| idna::domain_to_ascii_cow(black_box(encoded), idna::AsciiDenyList::URL)); +} + benchmark_group!( benches, to_unicode_puny_label, @@ -58,5 +98,13 @@ benchmark_group!( to_ascii_already_puny_label, to_ascii_simple, to_ascii_merged, + to_ascii_cow_plain, + to_ascii_cow_leading_digit, + to_ascii_cow_unicode_mixed, + to_ascii_cow_punycode_mixed, + to_ascii_cow_unicode_ltr, + to_ascii_cow_punycode_ltr, + to_ascii_cow_unicode_rtl, + to_ascii_cow_punycode_rtl, ); benchmark_main!(benches); diff --git a/url/benches/parse_url.rs b/url/benches/parse_url.rs index cc87dda5c..3c9cd175e 100644 --- a/url/benches/parse_url.rs +++ b/url/benches/parse_url.rs @@ -19,5 +19,73 @@ fn long(bench: &mut Bencher) { bench.iter(|| black_box(url).parse::().unwrap()); } -benchmark_group!(benches, short, long); +fn plain(bench: &mut Bencher) { + let url = "https://example.com/"; + + bench.bytes = url.len() as u64; + bench.iter(|| black_box(url).parse::().unwrap()); +} + +fn leading_digit(bench: &mut Bencher) { + let url = "https://1test.example/"; + + bench.bytes = url.len() as u64; + bench.iter(|| black_box(url).parse::().unwrap()); +} + +fn unicode_mixed(bench: &mut Bencher) { + let url = "https://مثال.example/"; + + bench.bytes = url.len() as u64; + bench.iter(|| black_box(url).parse::().unwrap()); +} + +fn punycode_mixed(bench: &mut Bencher) { + let url = "https://xn--mgbh0fb.example/"; + + bench.bytes = url.len() as u64; + bench.iter(|| black_box(url).parse::().unwrap()); +} + +fn unicode_ltr(bench: &mut Bencher) { + let url = "https://නම.උදාහරණ/"; + + bench.bytes = url.len() as u64; + bench.iter(|| black_box(url).parse::().unwrap()); +} + +fn punycode_ltr(bench: &mut Bencher) { + let url = "https://xn--r0co.xn--ozc8dl2c3bxd/"; + + bench.bytes = url.len() as u64; + bench.iter(|| black_box(url).parse::().unwrap()); +} + +fn unicode_rtl(bench: &mut Bencher) { + let url = "https://الاسم.مثال/"; + + bench.bytes = url.len() as u64; + bench.iter(|| black_box(url).parse::().unwrap()); +} + +fn punycode_rtl(bench: &mut Bencher) { + let url = "https://xn--mgba0b1dh.xn--mgbh0fb/"; + + bench.bytes = url.len() as u64; + bench.iter(|| black_box(url).parse::().unwrap()); +} + +benchmark_group!( + benches, + short, + long, + plain, + leading_digit, + unicode_mixed, + punycode_mixed, + unicode_ltr, + punycode_ltr, + unicode_rtl, + punycode_rtl, +); benchmark_main!(benches);