summaryrefslogtreecommitdiffstats
path: root/vendor/intl_pluralrules/benches
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:02:58 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:02:58 +0000
commit698f8c2f01ea549d77d7dc3338a12e04c11057b9 (patch)
tree173a775858bd501c378080a10dca74132f05bc50 /vendor/intl_pluralrules/benches
parentInitial commit. (diff)
downloadrustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.tar.xz
rustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.zip
Adding upstream version 1.64.0+dfsg1.upstream/1.64.0+dfsg1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/intl_pluralrules/benches')
-rw-r--r--vendor/intl_pluralrules/benches/pluralrules.rs69
1 files changed, 69 insertions, 0 deletions
diff --git a/vendor/intl_pluralrules/benches/pluralrules.rs b/vendor/intl_pluralrules/benches/pluralrules.rs
new file mode 100644
index 000000000..c1e673aaa
--- /dev/null
+++ b/vendor/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);