| 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 |
mod fixtures; |
| 6 |
mod helpers; |
| 7 |
|
| 8 |
use criterion::{Criterion, black_box, criterion_group, criterion_main}; |
| 9 |
|
| 10 |
use icu_locale_core::Locale; |
| 11 |
|
| 12 |
fn locale_benches(c: &mut Criterion) { |
| 13 |
let data = serde_json::from_str::<fixtures::LocaleList>(include_str!("fixtures/locale.json")) |
| 14 |
.expect("Failed to read a fixture"); |
| 15 |
|
| 16 |
// Overview |
| 17 |
{ |
| 18 |
let mut group = c.benchmark_group("locale"); |
| 19 |
|
| 20 |
overview!(group, Locale, &data.canonicalized, "en-US"); |
| 21 |
|
| 22 |
group.finish(); |
| 23 |
} |
| 24 |
|
| 25 |
{ |
| 26 |
use criterion::BenchmarkId; |
| 27 |
|
| 28 |
// Construct |
| 29 |
{ |
| 30 |
let mut group = c.benchmark_group("locale/construct"); |
| 31 |
|
| 32 |
construct!(group, Locale, "locale", &data.canonicalized); |
| 33 |
|
| 34 |
group.finish(); |
| 35 |
} |
| 36 |
|
| 37 |
// Stringify |
| 38 |
{ |
| 39 |
let mut group = c.benchmark_group("locale/to_string"); |
| 40 |
|
| 41 |
let locales: Vec<Locale> = data |
| 42 |
.canonicalized |
| 43 |
.iter() |
| 44 |
.map(|s| s.parse().unwrap()) |
| 45 |
.collect(); |
| 46 |
|
| 47 |
to_string!(group, Locale, "locale", &locales); |
| 48 |
|
| 49 |
group.finish(); |
| 50 |
} |
| 51 |
|
| 52 |
// Compare |
| 53 |
{ |
| 54 |
let mut group = c.benchmark_group("locale/compare"); |
| 55 |
|
| 56 |
let locales: Vec<Locale> = data |
| 57 |
.canonicalized |
| 58 |
.iter() |
| 59 |
.map(|s| s.parse().unwrap()) |
| 60 |
.collect(); |
| 61 |
let locales2: Vec<Locale> = data |
| 62 |
.canonicalized |
| 63 |
.iter() |
| 64 |
.map(|s| s.parse().unwrap()) |
| 65 |
.collect(); |
| 66 |
|
| 67 |
compare_struct!(group, Locale, "locale", &locales, &locales2); |
| 68 |
|
| 69 |
compare_str!(group, Locale, "locale", &locales, &data.canonicalized); |
| 70 |
|
| 71 |
group.finish(); |
| 72 |
} |
| 73 |
|
| 74 |
// Canonicalize |
| 75 |
{ |
| 76 |
let mut group = c.benchmark_group("locale/canonicalize"); |
| 77 |
|
| 78 |
canonicalize!(group, Locale, "locale", &data.casing); |
| 79 |
|
| 80 |
group.finish(); |
| 81 |
} |
| 82 |
} |
| 83 |
} |
| 84 |
|
| 85 |
criterion_group!(benches, locale_benches,); |
| 86 |
criterion_main!(benches); |