summaryrefslogtreecommitdiffstats
path: root/vendor/icu_locid/benches/subtags.rs
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/icu_locid/benches/subtags.rs')
-rw-r--r--vendor/icu_locid/benches/subtags.rs39
1 files changed, 39 insertions, 0 deletions
diff --git a/vendor/icu_locid/benches/subtags.rs b/vendor/icu_locid/benches/subtags.rs
new file mode 100644
index 000000000..4f81b71d2
--- /dev/null
+++ b/vendor/icu_locid/benches/subtags.rs
@@ -0,0 +1,39 @@
+// 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 path = "./benches/fixtures/subtags.json";
+ let data: fixtures::Subtags = helpers::read_fixture(path).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);