bench/
bench.rs

1// Copyright 2021 System76 <info@system76.com>
2// SPDX-License-Identifier: MPL-2.0
3
4use std::{fs, time::Duration};
5
6use freedesktop_desktop_entry::{default_paths, get_languages_from_env, DesktopEntry, Iter};
7
8use std::time::Instant;
9
10fn main() {
11    let it = 500;
12
13    bench(it);
14}
15
16fn bench(it: u32) {
17    let mut total_time = Duration::ZERO;
18
19    for _ in 0..it {
20        let locale = get_languages_from_env();
21        let paths = Iter::new(default_paths());
22
23        let now = Instant::now();
24
25        for path in paths {
26            if let Ok(bytes) = fs::read_to_string(&path) {
27                if let Ok(_entry) = DesktopEntry::from_str(&path, &bytes, Some(&locale)) {}
28            }
29        }
30
31        total_time += now.elapsed();
32    }
33
34    println!("time to parse all .desktop files: {:.2?}", total_time / it);
35}