summaryrefslogtreecommitdiffstats
path: root/third_party/rust/intl_pluralrules/benches/pluralrules.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/intl_pluralrules/benches/pluralrules.rs
parentInitial commit. (diff)
downloadfirefox-esr-upstream.tar.xz
firefox-esr-upstream.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/intl_pluralrules/benches/pluralrules.rs')
-rw-r--r--third_party/rust/intl_pluralrules/benches/pluralrules.rs69
1 files changed, 69 insertions, 0 deletions
diff --git a/third_party/rust/intl_pluralrules/benches/pluralrules.rs b/third_party/rust/intl_pluralrules/benches/pluralrules.rs
new file mode 100644
index 0000000000..c1e673aaa1
--- /dev/null
+++ b/third_party/rust/intl_pluralrules/benches/pluralrules.rs
@@ -0,0 +1,69 @@
+use criterion::criterion_group;
+use criterion::criterion_main;
+use criterion::BenchmarkId;
+use criterion::Criterion;
+
+use intl_pluralrules::{PluralRuleType, PluralRules};
+use unic_langid::{langid, LanguageIdentifier};
+
+fn plural_rules(c: &mut Criterion) {
+ let langs = &["uk", "de", "sk", "ar", "fr", "it", "en", "cs", "es", "zh"];
+ let langs: Vec<LanguageIdentifier> = langs
+ .iter()
+ .map(|l| l.parse().expect("Parsing failed"))
+ .collect();
+
+ c.bench_with_input(
+ BenchmarkId::new("construct", langs.len()),
+ &langs,
+ |b, langs| {
+ b.iter(|| {
+ for lang in langs {
+ PluralRules::create(lang.clone(), PluralRuleType::ORDINAL).unwrap();
+ PluralRules::create(lang.clone(), PluralRuleType::CARDINAL).unwrap();
+ }
+ });
+ },
+ );
+
+ let samples = &[
+ 1, 2, 3, 4, 5, 25, 134, 910293019, 12, 1412, -12, 15, 2931, 31231, 3123, 13231, 91, 0, 231,
+ -2, -45, 33, 728, 2, 291, 24, 479, 291, 778, 919, 93,
+ ];
+
+ let langid_pl = langid!("pl");
+ let ipr = PluralRules::create(langid_pl.clone(), PluralRuleType::CARDINAL).unwrap();
+
+ c.bench_with_input(
+ BenchmarkId::new("select", samples.len()),
+ samples,
+ |b, samples| {
+ b.iter(|| {
+ for value in samples {
+ ipr.select(*value).unwrap();
+ }
+ });
+ },
+ );
+
+ c.bench_function("total", |b| {
+ b.iter(|| {
+ let ipr = PluralRules::create(langid_pl.clone(), PluralRuleType::CARDINAL).unwrap();
+ ipr.select(1).unwrap();
+ ipr.select(2).unwrap();
+ ipr.select(3).unwrap();
+ ipr.select(4).unwrap();
+ ipr.select(5).unwrap();
+ ipr.select(25).unwrap();
+ ipr.select(134).unwrap();
+ ipr.select(5090).unwrap();
+ ipr.select(910293019).unwrap();
+ ipr.select(5.2).unwrap();
+ ipr.select(-0.2).unwrap();
+ ipr.select("12.06").unwrap();
+ })
+ });
+}
+
+criterion_group!(benches, plural_rules,);
+criterion_main!(benches);