diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:18:32 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:18:32 +0000 |
commit | 4547b622d8d29df964fa2914213088b148c498fc (patch) | |
tree | 9fc6b25f3c3add6b745be9a2400a6e96140046e9 /vendor/unic-langid-impl/benches | |
parent | Releasing progress-linux version 1.66.0+dfsg1-1~progress7.99u1. (diff) | |
download | rustc-4547b622d8d29df964fa2914213088b148c498fc.tar.xz rustc-4547b622d8d29df964fa2914213088b148c498fc.zip |
Merging upstream version 1.67.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/unic-langid-impl/benches')
-rw-r--r-- | vendor/unic-langid-impl/benches/likely_subtags.rs | 51 | ||||
-rw-r--r-- | vendor/unic-langid-impl/benches/parser.rs | 14 |
2 files changed, 32 insertions, 33 deletions
diff --git a/vendor/unic-langid-impl/benches/likely_subtags.rs b/vendor/unic-langid-impl/benches/likely_subtags.rs index a01666597..3b7f8746e 100644 --- a/vendor/unic-langid-impl/benches/likely_subtags.rs +++ b/vendor/unic-langid-impl/benches/likely_subtags.rs @@ -1,9 +1,8 @@ -use criterion::black_box; use criterion::criterion_group; use criterion::criterion_main; use criterion::Criterion; -use tinystr::{TinyStr4, TinyStr8}; +use unic_langid_impl::subtags; use unic_langid_impl::LanguageIdentifier; static STRINGS: &[&str] = &[ @@ -49,51 +48,37 @@ static STRINGS: &[&str] = &[ ]; fn maximize_bench(c: &mut Criterion) { + let langids: Vec<LanguageIdentifier> = STRINGS + .iter() + .map(|s| -> LanguageIdentifier { s.parse().unwrap() }) + .collect(); c.bench_function("maximize", move |b| { b.iter(|| { - let langids: Vec<LanguageIdentifier> = STRINGS - .iter() - .map(|s| -> LanguageIdentifier { s.parse().unwrap() }) - .collect(); - for mut s in langids { + for mut s in langids.clone().into_iter() { s.maximize(); - let _ = black_box(s.to_string()); } }) }); } -fn extract_input(s: &str) -> (Option<TinyStr8>, Option<TinyStr4>, Option<TinyStr4>) { - let chunks: Vec<&str> = s.split("-").collect(); - let mut lang: Option<TinyStr8> = chunks.get(0).map(|s| s.parse().unwrap()); - let mut script: Option<TinyStr4> = chunks.get(1).map(|s| s.parse().unwrap()); - let mut region: Option<TinyStr4> = chunks.get(2).map(|s| s.parse().unwrap()); - if let Some(l) = lang { - if l.as_str() == "und" { - lang = None; - } - } - if let Some(s) = script { - if s.as_str().chars().count() == 2 { - region = script; - script = None; - } - } - (lang, script, region) +fn extract_input( + s: &str, +) -> ( + subtags::Language, + Option<subtags::Script>, + Option<subtags::Region>, +) { + let langid: LanguageIdentifier = s.parse().unwrap(); + (langid.language, langid.script, langid.region) } fn raw_maximize_bench(c: &mut Criterion) { - let entries: Vec<(Option<TinyStr8>, Option<TinyStr4>, Option<TinyStr4>)> = - STRINGS.iter().map(|s| extract_input(s)).collect(); + let entries: Vec<_> = STRINGS.iter().map(|s| extract_input(s)).collect(); c.bench_function("raw_maximize", move |b| { b.iter(|| { - for (lang, script, region) in &entries { - let _ = unic_langid_impl::likelysubtags::maximize( - lang.clone(), - script.clone(), - region.clone(), - ); + for (lang, script, region) in entries.clone().into_iter() { + let _ = unic_langid_impl::likelysubtags::maximize(lang, script, region); } }) }); diff --git a/vendor/unic-langid-impl/benches/parser.rs b/vendor/unic-langid-impl/benches/parser.rs index 43c7a3282..97abe833f 100644 --- a/vendor/unic-langid-impl/benches/parser.rs +++ b/vendor/unic-langid-impl/benches/parser.rs @@ -21,6 +21,13 @@ fn language_identifier_parser_bench(c: &mut Criterion) { "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| { @@ -49,6 +56,13 @@ fn language_identifier_parser_casing_bench(c: &mut Criterion) { "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(); |