| 1 |
// This file is part of ICU4X. For terms of use, please see the file |
| 2 |
// called LICENSE at the top level of the ICU4X source tree |
| 3 |
// (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ). |
| 4 |
|
| 5 |
#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)] |
| 6 |
pub(crate) struct PatternsFixture(pub(crate) Vec<String>); |
| 7 |
|
| 8 |
use criterion::{Criterion, criterion_group, criterion_main}; |
| 9 |
|
| 10 |
use icu_datetime::provider::pattern::reference::Pattern; |
| 11 |
|
| 12 |
fn pattern_benches(c: &mut Criterion) { |
| 13 |
let patterns = serde_json::from_str::<PatternsFixture>(include_str!("fixtures/patterns.json")) |
| 14 |
.unwrap() |
| 15 |
.0; |
| 16 |
|
| 17 |
{ |
| 18 |
let mut group = c.benchmark_group("pattern"); |
| 19 |
|
| 20 |
group.bench_function("parse", |b| { |
| 21 |
b.iter(|| { |
| 22 |
for input in &patterns { |
| 23 |
let _ = input.parse::<Pattern>().unwrap(); |
| 24 |
} |
| 25 |
}) |
| 26 |
}); |
| 27 |
|
| 28 |
group.finish(); |
| 29 |
} |
| 30 |
} |
| 31 |
|
| 32 |
criterion_group!(benches, pattern_benches,); |
| 33 |
criterion_main!(benches); |