cosmic-freedesktop-icons/benches/simple_lookup.rs

77 lines
2.5 KiB
Rust
Raw Normal View History

use criterion::{
AxisScale, BenchmarkId, Criterion, PlotConfiguration, black_box, criterion_group,
criterion_main,
};
use freedesktop_icons::lookup;
use gtk4::{IconLookupFlags, IconTheme, TextDirection};
2022-05-13 07:59:33 +02:00
pub fn bench_lookups(c: &mut Criterion) {
let mut group = c.benchmark_group("ComparisonsLookups");
let plot_config = PlotConfiguration::default().summary_scale(AxisScale::Logarithmic);
group.plot_config(plot_config);
2022-05-13 07:59:33 +02:00
let args = [
"user-home", // (Best case) An icon that can be found in the current theme
"firefox", // An icon that can be found in the hicolor default theme
2022-05-13 08:36:58 +02:00
"archlinux-logo", // An icon that resides in /usr/share/pixmaps
"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:36:58 +02:00
group.bench_with_input(BenchmarkId::new("freedesktop-icons", arg), arg, |b, arg| {
b.iter(|| {
lookup(black_box(arg))
.with_theme(black_box("Adwaita"))
.find()
});
2022-05-13 08:36:58 +02:00
});
2022-05-13 08:01:21 +02:00
group.bench_with_input(
2022-05-13 08:36:58 +02:00
BenchmarkId::new("freedesktop-icons-cache", arg),
2022-05-13 08:01:21 +02:00
arg,
|b, arg| {
b.iter(|| {
lookup(black_box(arg))
.with_scale(black_box(1))
.with_size(black_box(24))
.with_theme(black_box("Adwaita"))
.with_cache()
.find()
});
2022-05-13 08:01:21 +02:00
},
);
2022-05-13 07:59:33 +02:00
2022-05-13 08:36:58 +02:00
group.bench_with_input(BenchmarkId::new("linicon", arg), arg, |b, arg| {
b.iter(|| {
linicon::lookup_icon(black_box(arg))
.from_theme(black_box("Adwaita"))
.with_scale(black_box(1))
.with_size(black_box(24))
.next()
});
2022-05-13 07:59:33 +02:00
});
2022-05-13 08:36:58 +02:00
group.bench_with_input(BenchmarkId::new("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(
black_box(arg),
black_box(&[]),
black_box(24),
black_box(1),
black_box(TextDirection::None),
black_box(IconLookupFlags::empty()),
)
.icon_name()
2022-05-13 07:59:33 +02:00
});
});
}
2022-05-13 08:16:30 +02:00
group.finish();
}
criterion_group!(benches, bench_lookups);
criterion_main!(benches);