Sha256: a085b60cf4aeedde1b4f95502fed3c06eeb0d3e5903244925e9d1639cf819aec

Contents?: true

Size: 1.32 KB

Versions: 3

Compression:

Stored size: 1.32 KB

Contents

// 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::subtags::{Language, Region, Script, Variant};
use icu_locid::ParserError;

macro_rules! subtag_bench {
    ($c:expr, $name:expr, $subtag:ident, $data:expr) => {
        $c.bench_function(&format!("subtags/{}/parse", $name), |b| {
            b.iter(|| {
                for s in &$data.valid {
                    let _: $subtag = black_box(s).parse().unwrap();
                }
                for s in &$data.invalid {
                    let _: ParserError = black_box(s).parse::<$subtag>().unwrap_err();
                }
            })
        });
    };
}

fn subtags_bench(c: &mut Criterion) {
    let data = serde_json::from_str::<fixtures::Subtags>(include_str!("fixtures/subtags.json"))
        .expect("Failed to read a fixture");

    subtag_bench!(c, "language", Language, data.language);
    subtag_bench!(c, "script", Script, data.script);
    subtag_bench!(c, "region", Region, data.region);
    subtag_bench!(c, "variant", Variant, data.variant);
}

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

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
wasmtime-29.0.0 ./ext/cargo-vendor/icu_locid-1.5.0/benches/subtags.rs
wasmtime-28.0.0 ./ext/cargo-vendor/icu_locid-1.5.0/benches/subtags.rs
wasmtime-27.0.0 ./ext/cargo-vendor/icu_locid-1.5.0/benches/subtags.rs