forked from servo/rust-url
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparse_url.rs
More file actions
113 lines (86 loc) · 2.65 KB
/
parse_url.rs
File metadata and controls
113 lines (86 loc) · 2.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#[macro_use]
extern crate bencher;
use bencher::{black_box, Bencher};
use url::Url;
fn short(bench: &mut Bencher) {
let url = "https://example.com/bench";
bench.bytes = url.len() as u64;
bench.iter(|| black_box(url).parse::<Url>().unwrap());
}
fn long(bench: &mut Bencher) {
let url = "https://example.com/parkbench?tre=es&st=uff";
bench.bytes = url.len() as u64;
bench.iter(|| black_box(url).parse::<Url>().unwrap());
}
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 hyphen(bench: &mut Bencher) {
let url = "https://hyphenated-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());
}
fn url_to_file_path(bench: &mut Bencher) {
let url = if cfg!(windows) {
"file:///C:/dir/next_dir/sub_sub_dir/testing/testing.json"
} else {
"file:///data/dir/next_dir/sub_sub_dir/testing/testing.json"
};
let url = url.parse::<Url>().unwrap();
bench.iter(|| {
black_box(url.to_file_path().unwrap());
});
}
benchmark_group!(
benches,
short,
long,
plain,
hyphen,
leading_digit,
unicode_mixed,
punycode_mixed,
unicode_ltr,
punycode_ltr,
unicode_rtl,
punycode_rtl,
url_to_file_path
);
benchmark_main!(benches);