perf: improve benchmarks
This commit is contained in:
parent
bee9d45dd3
commit
bc903c1bcb
1 changed files with 57 additions and 30 deletions
|
|
@ -1,38 +1,65 @@
|
||||||
use criterion::{criterion_group, criterion_main, Criterion};
|
use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion};
|
||||||
use freedesktop_icons::lookup;
|
use freedesktop_icons::lookup;
|
||||||
use gtk4::{IconLookupFlags, IconTheme, TextDirection};
|
use gtk4::{IconLookupFlags, IconTheme, TextDirection};
|
||||||
|
|
||||||
pub fn simple_lookup(c: &mut Criterion) {
|
pub fn simple_bench(c: &mut Criterion) {
|
||||||
c.bench_function("lookup firefox", |b| b.iter(|| lookup("firefox").find()));
|
c.bench_function("firefox lookup", |b| b.iter(||
|
||||||
|
lookup("firefox")
|
||||||
|
.with_theme("Papirus")
|
||||||
|
.with_cache()
|
||||||
|
.find()
|
||||||
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn simple_lookup_linicon(c: &mut Criterion) {
|
pub fn bench_lookups(c: &mut Criterion) {
|
||||||
c.bench_function("lookup firefox linicon", |b| {
|
let mut group = c.benchmark_group("ComparisonsLookups");
|
||||||
b.iter(|| linicon::lookup_icon("firefox").next().unwrap().unwrap())
|
|
||||||
|
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
|
||||||
|
"archlinux-logo", // An icon that resides in /usr/share/pixmap
|
||||||
|
"not-found", // (Worst case) An icon that does not exist
|
||||||
|
];
|
||||||
|
|
||||||
|
for arg in args {
|
||||||
|
group.bench_with_input(BenchmarkId::new("freedesktop-icons lookup", arg), arg, |b, arg| {
|
||||||
|
b.iter(|| lookup(arg)
|
||||||
|
.with_theme("Arc")
|
||||||
|
.find());
|
||||||
});
|
});
|
||||||
}
|
|
||||||
|
|
||||||
pub fn simple_lookup_gtk(c: &mut Criterion) {
|
group.bench_with_input(BenchmarkId::new("lookup with cache", arg), arg, |b, arg| {
|
||||||
c.bench_function("lookup firefox gkt", |b| {
|
b.iter(|| lookup(arg)
|
||||||
|
.with_theme("Arc")
|
||||||
|
.with_cache()
|
||||||
|
.find());
|
||||||
|
});
|
||||||
|
|
||||||
|
group.bench_with_input(BenchmarkId::new("lookup linicon", arg), arg, |b, arg| {
|
||||||
|
b.iter(|| linicon::lookup_icon(arg)
|
||||||
|
.from_theme("Arc")
|
||||||
|
.next());
|
||||||
|
});
|
||||||
|
|
||||||
|
group.bench_with_input(BenchmarkId::new("lookup gtk", arg), arg, |b, arg| {
|
||||||
gtk4::init().unwrap();
|
gtk4::init().unwrap();
|
||||||
let theme = IconTheme::new();
|
let theme = IconTheme::new();
|
||||||
b.iter(|| {
|
b.iter(|| {
|
||||||
theme.lookup_icon(
|
theme.lookup_icon(
|
||||||
"firefox",
|
arg,
|
||||||
&[],
|
&[],
|
||||||
24,
|
24,
|
||||||
1,
|
1,
|
||||||
TextDirection::None,
|
TextDirection::None,
|
||||||
IconLookupFlags::empty(),
|
IconLookupFlags::empty(),
|
||||||
)
|
)
|
||||||
})
|
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
group.finish();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
criterion_group!(
|
criterion_group!(benches, simple_bench, bench_lookups);
|
||||||
benches,
|
|
||||||
simple_lookup,
|
|
||||||
simple_lookup_linicon,
|
|
||||||
simple_lookup_gtk
|
|
||||||
);
|
|
||||||
criterion_main!(benches);
|
criterion_main!(benches);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue