Debian Codegraph @

debian/missing-sources/idna/benches/all.rs

raw
1 #![allow(deprecated)]
2
3 #[macro_use]
4 extern crate bencher;
5 extern crate idna;
6
7 use bencher::{black_box, Bencher};
8 use idna::Config;
9
10 fn to_unicode_puny_label(bench: &mut Bencher) {
11 let encoded = "abc.xn--mgbcm";
12 let config = Config::default();
13 bench.iter(|| config.to_unicode(black_box(encoded)));
14 }
15
16 fn to_ascii_already_puny_label(bench: &mut Bencher) {
17 let encoded = "abc.xn--mgbcm";
18 let config = Config::default();
19 bench.iter(|| config.to_ascii(black_box(encoded)));
20 }
21
22 fn to_unicode_ascii(bench: &mut Bencher) {
23 let encoded = "example.com";
24 let config = Config::default();
25 bench.iter(|| config.to_unicode(black_box(encoded)));
26 }
27
28 fn to_unicode_merged_label(bench: &mut Bencher) {
29 let encoded = "Beispiel.xn--vermgensberater-ctb";
30 let config = Config::default();
31 bench.iter(|| config.to_unicode(black_box(encoded)));
32 }
33
34 fn to_ascii_puny_label(bench: &mut Bencher) {
35 let encoded = "abc.ابج";
36 let config = Config::default();
37 bench.iter(|| config.to_ascii(black_box(encoded)));
38 }
39
40 fn to_ascii_simple(bench: &mut Bencher) {
41 let encoded = "example.com";
42 let config = Config::default();
43 bench.iter(|| config.to_ascii(black_box(encoded)));
44 }
45
46 fn to_ascii_merged(bench: &mut Bencher) {
47 let encoded = "beispiel.vermögensberater";
48 let config = Config::default();
49 bench.iter(|| config.to_ascii(black_box(encoded)));
50 }
51
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_hyphen(bench: &mut Bencher) {
58 let encoded = "hyphenated-example.com".as_bytes();
59 bench.iter(|| idna::domain_to_ascii_cow(black_box(encoded), idna::AsciiDenyList::URL));
60 }
61
62 fn to_ascii_cow_leading_digit(bench: &mut Bencher) {
63 let encoded = "1test.example".as_bytes();
64 bench.iter(|| idna::domain_to_ascii_cow(black_box(encoded), idna::AsciiDenyList::URL));
65 }
66
67 fn to_ascii_cow_unicode_mixed(bench: &mut Bencher) {
68 let encoded = "مثال.example".as_bytes();
69 bench.iter(|| idna::domain_to_ascii_cow(black_box(encoded), idna::AsciiDenyList::URL));
70 }
71
72 fn to_ascii_cow_punycode_mixed(bench: &mut Bencher) {
73 let encoded = "xn--mgbh0fb.example".as_bytes();
74 bench.iter(|| idna::domain_to_ascii_cow(black_box(encoded), idna::AsciiDenyList::URL));
75 }
76
77 fn to_ascii_cow_unicode_ltr(bench: &mut Bencher) {
78 let encoded = "නම.උදාහරණ".as_bytes();
79 bench.iter(|| idna::domain_to_ascii_cow(black_box(encoded), idna::AsciiDenyList::URL));
80 }
81
82 fn to_ascii_cow_punycode_ltr(bench: &mut Bencher) {
83 let encoded = "xn--r0co.xn--ozc8dl2c3bxd".as_bytes();
84 bench.iter(|| idna::domain_to_ascii_cow(black_box(encoded), idna::AsciiDenyList::URL));
85 }
86
87 fn to_ascii_cow_unicode_rtl(bench: &mut Bencher) {
88 let encoded = "الاسم.مثال".as_bytes();
89 bench.iter(|| idna::domain_to_ascii_cow(black_box(encoded), idna::AsciiDenyList::URL));
90 }
91
92 fn to_ascii_cow_punycode_rtl(bench: &mut Bencher) {
93 let encoded = "xn--mgba0b1dh.xn--mgbh0fb".as_bytes();
94 bench.iter(|| idna::domain_to_ascii_cow(black_box(encoded), idna::AsciiDenyList::URL));
95 }
96
97 benchmark_group!(
98 benches,
99 to_unicode_puny_label,
100 to_unicode_ascii,
101 to_unicode_merged_label,
102 to_ascii_puny_label,
103 to_ascii_already_puny_label,
104 to_ascii_simple,
105 to_ascii_merged,
106 to_ascii_cow_plain,
107 to_ascii_cow_hyphen,
108 to_ascii_cow_leading_digit,
109 to_ascii_cow_unicode_mixed,
110 to_ascii_cow_punycode_mixed,
111 to_ascii_cow_unicode_ltr,
112 to_ascii_cow_punycode_ltr,
113 to_ascii_cow_unicode_rtl,
114 to_ascii_cow_punycode_rtl,
115 );
116 benchmark_main!(benches);