summaryrefslogtreecommitdiffstats
path: root/third_party/rust/unic-langid-impl/benches/parser.rs
blob: 97abe833fb94b6e5b2720007c4ecf6cff51aaaa0 (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
use criterion::black_box;
use criterion::criterion_group;
use criterion::criterion_main;
use criterion::Criterion;

use unic_langid_impl::parser::parse_language_identifier;

fn language_identifier_parser_bench(c: &mut Criterion) {
    let strings = &[
        "en-US",
        "en-GB",
        "es-AR",
        "it",
        "zh-Hans-CN",
        "de-AT",
        "pl",
        "fr-FR",
        "de-AT",
        "sr-Cyrl-SR",
        "nb-NO",
        "fr-FR",
        "mk",
        "uk",
        "en-US",
        "en-GB",
        "es-AR",
        "th",
        "de",
        "zh-Cyrl-HN",
        "en-Latn-US",
    ];

    c.bench_function("language_identifier_parser", |b| {
        let slices: Vec<&[u8]> = strings.iter().map(|s| s.as_bytes()).collect();
        b.iter(|| {
            for s in &slices {
                let _ = parse_language_identifier(black_box(s));
            }
        })
    });
}

fn language_identifier_parser_casing_bench(c: &mut Criterion) {
    let strings = &[
        "En_uS",
        "EN-GB",
        "ES-aR",
        "iT",
        "zH_HaNs_cN",
        "dE-aT",
        "Pl",
        "FR-FR",
        "de_AT",
        "sR-CyrL_sr",
        "NB-NO",
        "fr_fr",
        "Mk",
        "uK",
        "en-us",
        "en_gb",
        "ES-AR",
        "tH",
        "DE",
        "ZH_cyrl_hN",
        "eN-lAtN-uS",
    ];
    c.bench_function("language_identifier_parser_casing", |b| {
        let slices: Vec<&[u8]> = strings.iter().map(|s| s.as_bytes()).collect();
        b.iter(|| {
            for s in &slices {
                let _ = parse_language_identifier(black_box(s));
            }
        })
    });
}

criterion_group!(
    benches,
    language_identifier_parser_bench,
    language_identifier_parser_casing_bench,
);
criterion_main!(benches);