perf: refine benches and add somes test to ensure we are testing the correct inputs
This commit is contained in:
parent
ab3d5a67f2
commit
64fdb377dc
2 changed files with 141 additions and 16 deletions
|
|
@ -1,5 +1,6 @@
|
|||
use criterion::{
|
||||
criterion_group, criterion_main, AxisScale, BenchmarkId, Criterion, PlotConfiguration,
|
||||
black_box, criterion_group, criterion_main, AxisScale, BenchmarkId, Criterion,
|
||||
PlotConfiguration,
|
||||
};
|
||||
use freedesktop_icons::lookup;
|
||||
use gtk4::{IconLookupFlags, IconTheme, TextDirection};
|
||||
|
|
@ -10,42 +11,60 @@ pub fn bench_lookups(c: &mut Criterion) {
|
|||
group.plot_config(plot_config);
|
||||
|
||||
let args = [
|
||||
"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
|
||||
"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
|
||||
"archlinux-logo", // An icon that resides in /usr/share/pixmaps
|
||||
"not-found", // (Worst case) An icon that does not exist
|
||||
"not-found", // (Worst case) An icon that does not exist
|
||||
];
|
||||
|
||||
for arg in args {
|
||||
group.bench_with_input(BenchmarkId::new("freedesktop-icons", arg), arg, |b, arg| {
|
||||
b.iter(|| lookup(arg).with_theme("Arc").find());
|
||||
b.iter(|| {
|
||||
lookup(black_box(arg))
|
||||
.with_theme(black_box("Adwaita"))
|
||||
.find()
|
||||
});
|
||||
});
|
||||
|
||||
group.bench_with_input(
|
||||
BenchmarkId::new("freedesktop-icons-cache", arg),
|
||||
arg,
|
||||
|b, arg| {
|
||||
b.iter(|| lookup(arg).with_theme("Arc").with_cache().find());
|
||||
b.iter(|| {
|
||||
lookup(black_box(arg))
|
||||
.with_scale(black_box(1))
|
||||
.with_size(black_box(24))
|
||||
.with_theme(black_box("Adwaita"))
|
||||
.with_cache()
|
||||
.find()
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
group.bench_with_input(BenchmarkId::new("linicon", arg), arg, |b, arg| {
|
||||
b.iter(|| linicon::lookup_icon(arg).from_theme("Arc").next());
|
||||
b.iter(|| {
|
||||
linicon::lookup_icon(black_box(arg))
|
||||
.from_theme(black_box("Adwaita"))
|
||||
.with_scale(black_box(1))
|
||||
.with_size(black_box(24))
|
||||
.next()
|
||||
});
|
||||
});
|
||||
|
||||
group.bench_with_input(BenchmarkId::new("gtk", arg), arg, |b, arg| {
|
||||
gtk4::init().unwrap();
|
||||
let theme = IconTheme::new();
|
||||
b.iter(|| {
|
||||
theme.lookup_icon(
|
||||
arg,
|
||||
&[],
|
||||
24,
|
||||
1,
|
||||
TextDirection::None,
|
||||
IconLookupFlags::empty(),
|
||||
)
|
||||
theme
|
||||
.lookup_icon(
|
||||
black_box(arg),
|
||||
black_box(&[]),
|
||||
black_box(24),
|
||||
black_box(1),
|
||||
black_box(TextDirection::None),
|
||||
black_box(IconLookupFlags::empty()),
|
||||
)
|
||||
.icon_name()
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue