summaryrefslogtreecommitdiffstats
path: root/intl/l10n/rust/l10nregistry-rs/benches/preferences.rs
diff options
context:
space:
mode:
Diffstat (limited to 'intl/l10n/rust/l10nregistry-rs/benches/preferences.rs')
-rw-r--r--intl/l10n/rust/l10nregistry-rs/benches/preferences.rs65
1 files changed, 65 insertions, 0 deletions
diff --git a/intl/l10n/rust/l10nregistry-rs/benches/preferences.rs b/intl/l10n/rust/l10nregistry-rs/benches/preferences.rs
new file mode 100644
index 0000000000..e4405c6537
--- /dev/null
+++ b/intl/l10n/rust/l10nregistry-rs/benches/preferences.rs
@@ -0,0 +1,65 @@
+use criterion::criterion_group;
+use criterion::criterion_main;
+use criterion::Criterion;
+
+use fluent_testing::get_scenarios;
+use l10nregistry::testing::TestFileFetcher;
+
+use unic_langid::LanguageIdentifier;
+
+fn preferences_bench(c: &mut Criterion) {
+ let fetcher = TestFileFetcher::new();
+
+ let mut group = c.benchmark_group("registry/scenarios");
+
+ for scenario in get_scenarios() {
+ let res_ids = scenario.res_ids.clone();
+
+ let locales: Vec<LanguageIdentifier> = scenario
+ .locales
+ .iter()
+ .map(|l| l.parse().unwrap())
+ .collect();
+
+ group.bench_function(format!("{}/sync/first_bundle", scenario.name), |b| {
+ b.iter(|| {
+ let reg = fetcher.get_registry(&scenario);
+ let mut bundles =
+ reg.generate_bundles_sync(locales.clone().into_iter(), res_ids.clone());
+ for _ in 0..locales.len() {
+ if bundles.next().is_some() {
+ break;
+ }
+ }
+ })
+ });
+
+ #[cfg(feature = "tokio")]
+ {
+ use futures::stream::StreamExt;
+
+ let rt = tokio::runtime::Runtime::new().unwrap();
+
+ group.bench_function(&format!("{}/async/first_bundle", scenario.name), |b| {
+ b.iter(|| {
+ rt.block_on(async {
+ let reg = fetcher.get_registry(&scenario);
+
+ let mut bundles =
+ reg.generate_bundles(locales.clone().into_iter(), res_ids.clone());
+ for _ in 0..locales.len() {
+ if bundles.next().await.is_some() {
+ break;
+ }
+ }
+ });
+ })
+ });
+ }
+ }
+
+ group.finish();
+}
+
+criterion_group!(benches, preferences_bench);
+criterion_main!(benches);