cosmic-freedesktop-icons/benches/simple_lookup.rs

60 lines
2 KiB
Rust
Raw Normal View History

2022-05-13 07:59:33 +02:00
use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion};
use freedesktop_icons::lookup;
use gtk4::{IconLookupFlags, IconTheme, TextDirection};
2022-05-13 07:59:33 +02:00
pub fn simple_bench(c: &mut Criterion) {
2022-05-13 08:01:21 +02:00
c.bench_function("firefox lookup", |b| {
b.iter(|| lookup("firefox").with_theme("Papirus").with_cache().find())
});
}
2022-05-13 07:59:33 +02:00
pub fn bench_lookups(c: &mut Criterion) {
let mut group = c.benchmark_group("ComparisonsLookups");
let args = [
2022-05-13 08:01:21 +02:00
"user-home", // (Best case) An icon that can be found in the current theme
"video-single-display-symbolic", // An icon that can be found in the parent theme
"firefox", // An icon that can be found in the hicolor default theme
"archlinux-logo", // An icon that resides in /usr/share/pixmap
"not-found", // (Worst case) An icon that does not exist
2022-05-13 07:59:33 +02:00
];
for arg in args {
2022-05-13 08:01:21 +02:00
group.bench_with_input(
BenchmarkId::new("freedesktop-icons lookup", arg),
arg,
|b, arg| {
b.iter(|| lookup(arg).with_theme("Arc").find());
},
);
2022-05-13 07:59:33 +02:00
group.bench_with_input(BenchmarkId::new("lookup with cache", arg), arg, |b, arg| {
2022-05-13 08:01:21 +02:00
b.iter(|| lookup(arg).with_theme("Arc").with_cache().find());
2022-05-13 07:59:33 +02:00
});
group.bench_with_input(BenchmarkId::new("lookup linicon", arg), arg, |b, arg| {
2022-05-13 08:01:21 +02:00
b.iter(|| linicon::lookup_icon(arg).from_theme("Arc").next());
2022-05-13 07:59:33 +02:00
});
group.bench_with_input(BenchmarkId::new("lookup gtk", arg), arg, |b, arg| {
2022-05-13 08:01:21 +02:00
gtk4::init().unwrap();
let theme = IconTheme::new();
2022-05-13 07:59:33 +02:00
b.iter(|| {
theme.lookup_icon(
arg,
&[],
24,
1,
TextDirection::None,
IconLookupFlags::empty(),
)
});
});
}
2022-05-13 08:16:30 +02:00
group.finish();
}
2022-05-13 07:59:33 +02:00
criterion_group!(benches, simple_bench, bench_lookups);
criterion_main!(benches);