Skip to content

Commit

Permalink
Add benchmarks for the Color32 unmultiplied constructor
Browse files Browse the repository at this point in the history
It was noted that it is fairly slow, so this benchmark is added to
evaluate performance gains.
  • Loading branch information
YgorSouza committed Sep 8, 2024
1 parent 6b7f431 commit be76290
Showing 1 changed file with 34 additions and 1 deletion.
35 changes: 34 additions & 1 deletion crates/epaint/benches/benchmark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,36 @@ fn thin_large_line_uv(c: &mut Criterion) {
});
}

fn from_rgba_unmultiplied_0(c: &mut Criterion) {
c.bench_function("from_rgba_unmultiplied_0", move |b| {
let [r, g, bl, a] = black_box([20u8, 20, 20, 0]);
b.iter(|| {
let color = ecolor::Color32::from_rgba_unmultiplied(r, g, bl, a);
black_box(color);
});
});
}

fn from_rgba_unmultiplied_100(c: &mut Criterion) {
c.bench_function("from_rgba_unmultiplied_100", move |b| {
let [r, g, bl, a] = black_box([20u8, 20, 20, 100]);
b.iter(|| {
let color = ecolor::Color32::from_rgba_unmultiplied(r, g, bl, a);
black_box(color);
});
});
}

fn from_rgba_unmultiplied_255(c: &mut Criterion) {
c.bench_function("from_rgba_unmultiplied_255", move |b| {
let [r, g, bl, a] = black_box([20u8, 20, 20, 255]);
b.iter(|| {
let color = ecolor::Color32::from_rgba_unmultiplied(r, g, bl, a);
black_box(color);
});
});
}

criterion_group!(
benches,
single_dashed_lines,
Expand All @@ -235,6 +265,9 @@ criterion_group!(
thick_line_uv,
thick_large_line_uv,
thin_line_uv,
thin_large_line_uv
thin_large_line_uv,
from_rgba_unmultiplied_0,
from_rgba_unmultiplied_100,
from_rgba_unmultiplied_255,
);
criterion_main!(benches);

0 comments on commit be76290

Please sign in to comment.