summaryrefslogtreecommitdiffstats
path: root/intl/l10n/rust/l10nregistry-rs/benches/source.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 /intl/l10n/rust/l10nregistry-rs/benches/source.rs
parentInitial commit. (diff)
downloadfirefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz
firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip
Adding upstream version 115.7.0esr.upstream/115.7.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-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);