summaryrefslogtreecommitdiffstats
path: root/intl/l10n/rust/l10nregistry-rs/benches/source.rs
diff options
context:
space:
mode:
Diffstat (limited to 'intl/l10n/rust/l10nregistry-rs/benches/source.rs')
-rw-r--r--intl/l10n/rust/l10nregistry-rs/benches/source.rs60
1 files changed, 60 insertions, 0 deletions
diff --git a/intl/l10n/rust/l10nregistry-rs/benches/source.rs b/intl/l10n/rust/l10nregistry-rs/benches/source.rs
new file mode 100644
index 0000000000..35668781da
--- /dev/null
+++ b/intl/l10n/rust/l10nregistry-rs/benches/source.rs
@@ -0,0 +1,60 @@
+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 get_locales<S>(input: &[S]) -> Vec<LanguageIdentifier>
+where
+ S: AsRef<str>,
+{
+ input.iter().map(|s| s.as_ref().parse().unwrap()).collect()
+}
+
+fn source_bench(c: &mut Criterion) {
+ let fetcher = TestFileFetcher::new();
+
+ let mut group = c.benchmark_group("source/scenarios");
+
+ for scenario in get_scenarios() {
+ let res_ids = scenario.res_ids.clone();
+
+ let locales: Vec<LanguageIdentifier> = get_locales(&scenario.locales);
+
+ let sources: Vec<_> = scenario
+ .file_sources
+ .iter()
+ .map(|s| {
+ fetcher.get_test_file_source(&s.name, None, get_locales(&s.locales), &s.path_scheme)
+ })
+ .collect();
+
+ group.bench_function(format!("{}/has_file", scenario.name), |b| {
+ b.iter(|| {
+ for source in &sources {
+ for res_id in &res_ids {
+ source.has_file(&locales[0], &res_id);
+ }
+ }
+ })
+ });
+
+ group.bench_function(format!("{}/sync/fetch_file_sync", scenario.name), |b| {
+ b.iter(|| {
+ for source in &sources {
+ for res_id in &res_ids {
+ source.fetch_file_sync(&locales[0], &res_id, false);
+ }
+ }
+ })
+ });
+ }
+
+ group.finish();
+}
+
+criterion_group!(benches, source_bench);
+criterion_main!(benches);