summaryrefslogtreecommitdiffstats
path: root/vendor/icu_locid/benches/langid.rs
blob: e5c9b67340d8a3ac150f26a11efd002ac04407f9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
// This file is part of ICU4X. For terms of use, please see the file
// called LICENSE at the top level of the ICU4X source tree
// (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ).

mod fixtures;
mod helpers;

use criterion::{black_box, criterion_group, criterion_main, Criterion};

use icu_locid::LanguageIdentifier;

fn langid_benches(c: &mut Criterion) {
    let path = "./benches/fixtures/langid.json";
    let data: fixtures::LocaleList = helpers::read_fixture(path).expect("Failed to read a fixture");

    // Overview
    {
        let mut group = c.benchmark_group("langid");

        overview!(group, LanguageIdentifier, &data.canonicalized, "en-US");

        group.finish();
    }

    #[cfg(feature = "bench")]
    {
        use criterion::BenchmarkId;

        // Construct
        {
            let mut group = c.benchmark_group("langid/construct");

            construct!(group, LanguageIdentifier, "langid", &data.canonicalized);

            group.finish();
        }

        // Stringify
        {
            let mut group = c.benchmark_group("langid/to_string");

            let langids: Vec<LanguageIdentifier> = data
                .canonicalized
                .iter()
                .map(|s| s.parse().unwrap())
                .collect();

            to_string!(group, LanguageIdentifier, "langid", &langids);

            group.finish();
        }

        // Compare
        {
            let mut group = c.benchmark_group("langid/compare");

            let langids: Vec<LanguageIdentifier> = data
                .canonicalized
                .iter()
                .map(|s| s.parse().unwrap())
                .collect();
            let langids2: Vec<LanguageIdentifier> = data
                .canonicalized
                .iter()
                .map(|s| s.parse().unwrap())
                .collect();

            compare_struct!(group, LanguageIdentifier, "langid", &langids, &langids2);

            compare_str!(
                group,
                LanguageIdentifier,
                "langid",
                &langids,
                &data.canonicalized
            );

            group.finish();
        }

        // Canonicalize
        {
            let mut group = c.benchmark_group("langid/canonicalize");

            canonicalize!(group, LanguageIdentifier, "langid", &data.casing);

            group.finish();
        }
    }
}

criterion_group!(benches, langid_benches,);
criterion_main!(benches);