summaryrefslogtreecommitdiffstats
path: root/third_party/rust/unic-langid-impl/benches/langid.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
commit36d22d82aa202bb199967e9512281e9a53db42c9 (patch)
tree105e8c98ddea1c1e4784a60a5a6410fa416be2de /third_party/rust/unic-langid-impl/benches/langid.rs
parentInitial commit. (diff)
downloadfirefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz
firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'third_party/rust/unic-langid-impl/benches/langid.rs')
-rw-r--r--third_party/rust/unic-langid-impl/benches/langid.rs84
1 files changed, 84 insertions, 0 deletions
diff --git a/third_party/rust/unic-langid-impl/benches/langid.rs b/third_party/rust/unic-langid-impl/benches/langid.rs
new file mode 100644
index 0000000000..026c288602
--- /dev/null
+++ b/third_party/rust/unic-langid-impl/benches/langid.rs
@@ -0,0 +1,84 @@
+use criterion::black_box;
+use criterion::criterion_group;
+use criterion::criterion_main;
+use criterion::Criterion;
+use criterion::Fun;
+
+use unic_langid_impl::subtags;
+use unic_langid_impl::LanguageIdentifier;
+
+static STRINGS: &[&str] = &[
+ "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",
+];
+
+fn language_identifier_construct_bench(c: &mut Criterion) {
+ let langids: Vec<LanguageIdentifier> = STRINGS
+ .iter()
+ .map(|s| -> LanguageIdentifier { s.parse().unwrap() })
+ .collect();
+
+ let funcs = vec![
+ Fun::new("from_str", |b, _| {
+ b.iter(|| {
+ for s in STRINGS {
+ let _: Result<LanguageIdentifier, _> = black_box(s).parse();
+ }
+ })
+ }),
+ Fun::new("from_bytes", |b, _| {
+ let slices: Vec<&[u8]> = STRINGS.iter().map(|s| s.as_bytes()).collect();
+ b.iter(|| {
+ for s in &slices {
+ let _ = LanguageIdentifier::from_bytes(black_box(s));
+ }
+ })
+ }),
+ Fun::new("from_parts", |b, langids: &Vec<LanguageIdentifier>| {
+ let entries: Vec<(
+ subtags::Language,
+ Option<subtags::Script>,
+ Option<subtags::Region>,
+ Vec<subtags::Variant>,
+ )> = langids
+ .iter()
+ .cloned()
+ .map(|langid| langid.into_parts())
+ .collect();
+ b.iter(|| {
+ for (language, script, region, variants) in &entries {
+ let _ = LanguageIdentifier::from_parts(
+ language.clone(),
+ script.clone(),
+ region.clone(),
+ variants,
+ );
+ }
+ })
+ }),
+ ];
+
+ c.bench_functions("language_identifier_construct", funcs, langids);
+}
+
+criterion_group!(benches, language_identifier_construct_bench,);
+criterion_main!(benches);