Debian Codegraph @

debian/rust-vendor/icu_plurals/benches/pluralrules.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
7 use criterion::{Criterion, criterion_group, criterion_main};
8
9 use icu_plurals::{PluralRuleType, PluralRules};
10
11 fn pluralrules(c: &mut Criterion) {
12 let plurals_data =
13 serde_json::from_str::<fixtures::PluralsFixture>(include_str!("fixtures/plurals.json"))
14 .expect("Failed to read a fixture");
15 let numbers_data =
16 serde_json::from_str::<fixtures::NumbersFixture>(include_str!("fixtures/numbers.json"))
17 .expect("Failed to read a fixture");
18
19 c.bench_function("plurals/pluralrules/overview", |b| {
20 b.iter(|| {
21 for lang in &plurals_data.langs {
22 let pr =
23 PluralRules::try_new(lang.into(), PluralRuleType::Cardinal.into()).unwrap();
24 for s in &numbers_data.usize {
25 let _ = pr.category_for(*s);
26 }
27 }
28 })
29 });
30
31 {
32 use criterion::black_box;
33 use icu_locale_core::locale;
34
35 c.bench_function("plurals/pluralrules/construct/fs", |b| {
36 b.iter(|| {
37 for lang in &plurals_data.langs {
38 PluralRules::try_new(lang.into(), PluralRuleType::Ordinal.into()).unwrap();
39 PluralRules::try_new(lang.into(), PluralRuleType::Cardinal.into()).unwrap();
40 }
41 });
42 });
43
44 let pr =
45 PluralRules::try_new(locale!("ru").into(), PluralRuleType::Cardinal.into()).unwrap();
46 c.bench_function("plurals/pluralrules/select/fs", |b| {
47 b.iter(|| {
48 for s in &numbers_data.usize {
49 let _ = pr.category_for(black_box(*s));
50 }
51 })
52 });
53 }
54 }
55
56 criterion_group!(benches, pluralrules,);
57 criterion_main!(benches);