tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

source.rs (1665B)


      1 use criterion::criterion_group;
      2 use criterion::criterion_main;
      3 use criterion::Criterion;
      4 
      5 use fluent_testing::get_scenarios;
      6 use l10nregistry_tests::TestFileFetcher;
      7 
      8 use unic_langid::LanguageIdentifier;
      9 
     10 fn get_locales<S>(input: &[S]) -> Vec<LanguageIdentifier>
     11 where
     12    S: AsRef<str>,
     13 {
     14    input.iter().map(|s| s.as_ref().parse().unwrap()).collect()
     15 }
     16 
     17 fn source_bench(c: &mut Criterion) {
     18    let fetcher = TestFileFetcher::new();
     19 
     20    let mut group = c.benchmark_group("source/scenarios");
     21 
     22    for scenario in get_scenarios() {
     23        let res_ids = scenario.res_ids.clone();
     24 
     25        let locales: Vec<LanguageIdentifier> = get_locales(&scenario.locales);
     26 
     27        let sources: Vec<_> = scenario
     28            .file_sources
     29            .iter()
     30            .map(|s| {
     31                fetcher.get_test_file_source(&s.name, None, get_locales(&s.locales), &s.path_scheme)
     32            })
     33            .collect();
     34 
     35        group.bench_function(format!("{}/has_file", scenario.name), |b| {
     36            b.iter(|| {
     37                for source in &sources {
     38                    for res_id in &res_ids {
     39                        source.has_file(&locales[0], &res_id);
     40                    }
     41                }
     42            })
     43        });
     44 
     45        group.bench_function(format!("{}/sync/fetch_file_sync", scenario.name), |b| {
     46            b.iter(|| {
     47                for source in &sources {
     48                    for res_id in &res_ids {
     49                        source.fetch_file_sync(&locales[0], &res_id, false);
     50                    }
     51                }
     52            })
     53        });
     54    }
     55 
     56    group.finish();
     57 }
     58 
     59 criterion_group!(benches, source_bench);
     60 criterion_main!(benches);