|
1 |
| -use ada_url::Url; |
2 |
| -use criterion::{black_box, criterion_group, criterion_main, Criterion}; |
| 1 | +use criterion::{black_box, criterion_group, criterion_main, Criterion, Throughput}; |
3 | 2 |
|
4 |
| -const URL: &[&str] = &[ |
5 |
| - "https://www.google.com/", |
6 |
| - "webhp?hl=en&ictx=2&sa=X&ved=0ahUKEwil_", |
7 |
| - "oSxzJj8AhVtEFkFHTHnCGQQPQgI", |
8 |
| - "https://support.google.com/websearch/", |
9 |
| - "?p=ws_results_help&hl=en-CA&fg=1", |
| 3 | +const URLS: &[&str] = &[ |
| 4 | + "https://www.google.com/webhp?hl=en&ictx=2&sa=X&ved=0ahUKEwil_oSxzJj8AhVtEFkFHTHnCGQQPQgI", |
| 5 | + "https://support.google.com/websearch/?p=ws_results_help&hl=en-CA&fg=1", |
10 | 6 | "https://en.wikipedia.org/wiki/Dog#Roles_with_humans",
|
11 | 7 | "https://www.tiktok.com/@aguyandagolden/video/7133277734310038830",
|
12 |
| - "https://business.twitter.com/en/help/troubleshooting/", |
13 |
| - "how-twitter-ads-work.html?ref=web-twc-ao-gbl-adsinfo&utm_source=twc&utm_", |
14 |
| - "medium=web&utm_campaign=ao&utm_content=adsinfo", |
15 |
| - "https://images-na.ssl-images-amazon.com/images/I/", |
16 |
| - "41Gc3C8UysL.css?AUIClients/AmazonGatewayAuiAssets", |
| 8 | + "https://business.twitter.com/en/help/troubleshooting/how-twitter-ads-work.html?ref=web-twc-ao-gbl-adsinfo&utm_source=twc&utm_medium=web&utm_campaign=ao&utm_content=adsinfo", |
| 9 | + "https://images-na.ssl-images-amazon.com/images/I/41Gc3C8UysL.css?AUIClients/AmazonGatewayAuiAssets", |
17 | 10 | "https://www.reddit.com/?after=t3_zvz1ze",
|
18 | 11 | "https://www.reddit.com/login/?dest=https%3A%2F%2Fwww.reddit.com%2F",
|
19 |
| - "postgresql://other:9818274x1!!@localhost:5432/", |
20 |
| - "otherdb?connect_timeout=10&application_name=myapp", |
| 12 | + "postgresql://other:9818274x1!!@localhost:5432/otherdb?connect_timeout=10&application_name=myapp", |
21 | 13 | "http://192.168.1.1", // ipv4
|
22 | 14 | "http://[2606:4700:4700::1111]", // ipv6
|
23 | 15 | ];
|
24 | 16 |
|
25 |
| -fn bench_url_parse(b: &mut Criterion) { |
26 |
| - b.benchmark_group("url_parse") |
27 |
| - .bench_function("ada_parse", |b| { |
28 |
| - b.iter(|| { |
29 |
| - URL.iter().for_each(|url| { |
30 |
| - let _ = Url::parse(black_box(url), None); |
31 |
| - }); |
| 17 | +pub fn parse_benchmark(c: &mut Criterion) { |
| 18 | + let mut group = c.benchmark_group("parse"); |
| 19 | + group.throughput(Throughput::Bytes(URLS.iter().map(|u| u.len() as u64).sum())); |
| 20 | + group.bench_function("ada_url", |b| { |
| 21 | + b.iter(|| { |
| 22 | + URLS.iter().for_each(|url| { |
| 23 | + black_box(url).parse::<ada_url::Url>().unwrap(); |
32 | 24 | })
|
33 | 25 | })
|
34 |
| - .bench_function("servo_parse", |b| { |
35 |
| - b.iter(|| { |
36 |
| - URL.iter().for_each(|url| { |
37 |
| - let _ = url::Url::parse(black_box(url)); |
38 |
| - }); |
| 26 | + }); |
| 27 | + group.bench_function("url", |b| { |
| 28 | + b.iter(|| { |
| 29 | + URLS.iter().for_each(|url| { |
| 30 | + black_box(url).parse::<url::Url>().unwrap(); |
39 | 31 | })
|
40 |
| - }); |
| 32 | + }) |
| 33 | + }); |
| 34 | + group.finish(); |
41 | 35 | }
|
42 | 36 |
|
43 |
| -criterion_group!(benches, bench_url_parse); |
| 37 | +criterion_group!(benches, parse_benchmark); |
44 | 38 | criterion_main!(benches);
|
0 commit comments