Skip to content

Commit daa7155

Browse files
committed
Add a benchmark of pattern parsing.
This test case comes from the usecase of using URLPattern for implementing Compression Dictionary Transport. It is useful for showing off the forthcoming improvements to pattern parsing
1 parent 988fda2 commit daa7155

2 files changed

Lines changed: 24 additions & 0 deletions

File tree

Cargo.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,8 @@ icu_properties = "2"
1515

1616
[dev-dependencies]
1717
serde_json = "1.0.66"
18+
criterion = "0.5"
19+
20+
[[bench]]
21+
name = "parse_patterns"
22+
harness = false

benches/parse_patterns.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
use criterion::{black_box, criterion_group, criterion_main, Criterion};
2+
use urlpattern::quirks::{self, EcmaRegexp};
3+
4+
fn bench_parse_shipping_groups_summary(c: &mut Criterion) {
5+
c.bench_function("parse component-ShippingGroupsSummary.*.js", |b| {
6+
b.iter(|| {
7+
let input = quirks::process_construct_pattern_input(
8+
black_box(quirks::StringOrInit::String(
9+
"component-ShippingGroupsSummary.*.js".to_owned()
10+
)),
11+
black_box(Some("https://shop.app/web/")),
12+
);
13+
quirks::parse_pattern::<EcmaRegexp>(input.unwrap(), urlpattern::UrlPatternOptions::default()).unwrap();
14+
})
15+
});
16+
}
17+
18+
criterion_group!(benches, bench_parse_shipping_groups_summary);
19+
criterion_main!(benches);

0 commit comments

Comments
 (0)