Debian Codegraph @

debian/rust-vendor/icu_locale_core/benches/langid.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::{Criterion, black_box, criterion_group, criterion_main};
9
10 use icu_locale_core::LanguageIdentifier;
11
12 fn langid_benches(c: &mut Criterion) {
13 let data = serde_json::from_str::<fixtures::LocaleList>(include_str!("fixtures/langid.json"))
14 .expect("Failed to read a fixture");
15
16 // Overview
17 {
18 let mut group = c.benchmark_group("langid");
19
20 overview!(group, LanguageIdentifier, &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("langid/construct");
31
32 construct!(group, LanguageIdentifier, "langid", &data.canonicalized);
33
34 group.finish();
35 }
36
37 // Stringify
38 {
39 let mut group = c.benchmark_group("langid/to_string");
40
41 let langids: Vec<LanguageIdentifier> = data
42 .canonicalized
43 .iter()
44 .map(|s| s.parse().unwrap())
45 .collect();
46
47 to_string!(group, LanguageIdentifier, "langid", &langids);
48
49 group.finish();
50 }
51
52 // Compare
53 {
54 let mut group = c.benchmark_group("langid/compare");
55
56 let langids: Vec<LanguageIdentifier> = data
57 .canonicalized
58 .iter()
59 .map(|s| s.parse().unwrap())
60 .collect();
61 let langids2: Vec<LanguageIdentifier> = data
62 .canonicalized
63 .iter()
64 .map(|s| s.parse().unwrap())
65 .collect();
66
67 compare_struct!(group, LanguageIdentifier, "langid", &langids, &langids2);
68
69 compare_str!(
70 group,
71 LanguageIdentifier,
72 "langid",
73 &langids,
74 &data.canonicalized
75 );
76
77 group.finish();
78 }
79
80 // Canonicalize
81 {
82 let mut group = c.benchmark_group("langid/canonicalize");
83
84 canonicalize!(group, LanguageIdentifier, "langid", &data.casing);
85
86 group.finish();
87 }
88 }
89 }
90
91 criterion_group!(benches, langid_benches,);
92 criterion_main!(benches);