add benchmark

This commit is contained in:
saji 2024-07-30 22:32:39 -05:00
parent b239c47e63
commit 25ac7d584b

View file

@ -1,15 +1,27 @@
use criterion::{black_box, criterion_group, criterion_main, Criterion}; use criterion::{black_box, criterion_group, criterion_main, BenchmarkId, Criterion};
use image::{ImageReader, RgbImage};
fn fibonacci(n: u64) -> u64 { use pi_frame_server::dither::{DitherMethod, DitheredImage, Palette};
match n {
0 => 1,
1 => 1,
n => fibonacci(n-1) + fibonacci(n-2),
}
}
fn criterion_benchmark(c: &mut Criterion) { fn criterion_benchmark(c: &mut Criterion) {
c.bench_function("fib 20", |b| b.iter(|| fibonacci(black_box(20)))); let sample_file = "sample_0.tiff";
let image: RgbImage = ImageReader::open(format!("samples/{sample_file}"))
.expect("file exists")
.decode()
.expect("file is valid")
.into_rgb8();
c.bench_with_input(BenchmarkId::new("dither", "sample_0"), &image, |b, i| {
b.iter(|| {
let mut method = DitherMethod::Atkinson.get_ditherer();
let mut result = DitheredImage::new(
image.width(),
image.height(),
Palette::Default.value().to_vec(),
);
method.dither(i, &mut result);
});
});
} }
criterion_group!(benches, criterion_benchmark); criterion_group!(benches, criterion_benchmark);