Skip to content

Add benches that use the main idna 1.0 entry point in idna and url #950

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions idna/benches/all.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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);
70 changes: 69 additions & 1 deletion url/benches/parse_url.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,73 @@ fn long(bench: &mut Bencher) {
bench.iter(|| black_box(url).parse::<Url>().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::<Url>().unwrap());
}

fn leading_digit(bench: &mut Bencher) {
let url = "https://1test.example/";

bench.bytes = url.len() as u64;
bench.iter(|| black_box(url).parse::<Url>().unwrap());
}

fn unicode_mixed(bench: &mut Bencher) {
let url = "https://مثال.example/";

bench.bytes = url.len() as u64;
bench.iter(|| black_box(url).parse::<Url>().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::<Url>().unwrap());
}

fn unicode_ltr(bench: &mut Bencher) {
let url = "https://නම.උදාහරණ/";

bench.bytes = url.len() as u64;
bench.iter(|| black_box(url).parse::<Url>().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::<Url>().unwrap());
}

fn unicode_rtl(bench: &mut Bencher) {
let url = "https://الاسم.مثال/";

bench.bytes = url.len() as u64;
bench.iter(|| black_box(url).parse::<Url>().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::<Url>().unwrap());
}

benchmark_group!(
benches,
short,
long,
plain,
leading_digit,
unicode_mixed,
punycode_mixed,
unicode_ltr,
punycode_ltr,
unicode_rtl,
punycode_rtl,
);
benchmark_main!(benches);