Debian Codegraph @

third_party/rust/icu_locid/benches/locale.rs

raw
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::{black_box, criterion_group, criterion_main, Criterion};
9
10 use icu_locid::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 #[cfg(feature = "bench")]
26 {
27 use criterion::BenchmarkId;
28
29 // Construct
30 {
31 let mut group = c.benchmark_group("locale/construct");
32
33 construct!(group, Locale, "locale", &data.canonicalized);
34
35 group.finish();
36 }
37
38 // Stringify
39 {
40 let mut group = c.benchmark_group("locale/to_string");
41
42 let locales: Vec<Locale> = data
43 .canonicalized
44 .iter()
45 .map(|s| s.parse().unwrap())
46 .collect();
47
48 to_string!(group, Locale, "locale", &locales);
49
50 group.finish();
51 }
52
53 // Compare
54 {
55 let mut group = c.benchmark_group("locale/compare");
56
57 let locales: Vec<Locale> = data
58 .canonicalized
59 .iter()
60 .map(|s| s.parse().unwrap())
61 .collect();
62 let locales2: Vec<Locale> = data
63 .canonicalized
64 .iter()
65 .map(|s| s.parse().unwrap())
66 .collect();
67
68 compare_struct!(group, Locale, "locale", &locales, &locales2);
69
70 compare_str!(group, Locale, "locale", &locales, &data.canonicalized);
71
72 group.finish();
73 }
74
75 // Canonicalize
76 {
77 let mut group = c.benchmark_group("locale/canonicalize");
78
79 canonicalize!(group, Locale, "locale", &data.casing);
80
81 group.finish();
82 }
83 }
84 }
85
86 criterion_group!(benches, locale_benches,);
87 criterion_main!(benches);