diff --git a/Cargo.toml b/Cargo.toml index 627fe22..340e8dd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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 diff --git a/benches/parsing.rs b/benches/parsing.rs new file mode 100644 index 0000000..ac70e88 --- /dev/null +++ b/benches/parsing.rs @@ -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);