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

use unic_langid_impl::canonicalize;

fn langid_canonicalize_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("langid_canonicalize", |b| {
        b.iter(|| {
            for s in strings {
                let _ = canonicalize(black_box(s));
            }
        })
    });
    c.bench_function("langid_canonicalize_from_bytes", |b| {
        let slices: Vec<&[u8]> = strings.iter().map(|s| s.as_bytes()).collect();
        b.iter(|| {
            for s in &slices {
                let _ = canonicalize(black_box(s));
            }
        })
    });
}

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