Skip to content

Commit

Permalink
Add parsing benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
rubdos committed Jun 20, 2023
1 parent e83afd7 commit 9a909f8
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
5 changes: 5 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,8 @@ doc-comment = "0.3"
rstest = "0.17"
rstest_reuse = "0.5"
anyhow = "1"
criterion = "0.5"

[[bench]]
name = "parsing"
harness = false
29 changes: 29 additions & 0 deletions benches/parsing.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
use criterion::{black_box, criterion_group, criterion_main, BenchmarkId, Criterion};

pub fn criterion_benchmark(c: &mut Criterion) {
let cases = [
"+80012340000",
"+61406823897",
"+611900123456",
"+32474091150",
"+34666777888",
"+34612345678",
"+441212345678",
"+13459492311",
"+16137827274",
"+1 520 878 2491",
"+1-520-878-2491",
];

for case in cases {
c.bench_with_input(BenchmarkId::new("parse", case), &case, |b, case| {
b.iter(|| {
let pn = black_box(case);
phonenumber::parse(None, pn)
})
});
}
}

criterion_group!(benches, criterion_benchmark);
criterion_main!(benches);

0 comments on commit 9a909f8

Please sign in to comment.