Skip to content

Commit

Permalink
add rgb benchmarks to for the filter function
Browse files Browse the repository at this point in the history
  • Loading branch information
ripytide committed May 27, 2024
1 parent 5e00bd1 commit a41dc3b
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions src/filter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1034,10 +1034,28 @@ mod benches {
}
};
}
macro_rules! bench_filter_clamped_rgb {
($name:ident, $kernel_size:expr, $image_size:expr, $function_name:ident) => {
#[bench]
fn $name(b: &mut Bencher) {
let image = rgb_bench_image(500, 500);

let kernel: Vec<i32> = (0..$kernel_size * $kernel_size).collect();
let kernel = Kernel::new(&kernel, $kernel_size, $kernel_size);
b.iter(|| {
let filtered: Image<Rgb<i16>> = $function_name::<_, _, i16>(&image, kernel);
black_box(filtered);
});
}
};
}

bench_filter_clamped_gray!(bench_filter_clamped_gray_3x3, 3, 300, filter_clamped);
bench_filter_clamped_gray!(bench_filter_clamped_gray_5x5, 5, 300, filter_clamped);
bench_filter_clamped_gray!(bench_filter_clamped_gray_7x7, 7, 300, filter_clamped);
bench_filter_clamped_rgb!(bench_filter_clamped_rgb_3x3, 3, 300, filter_clamped);
bench_filter_clamped_rgb!(bench_filter_clamped_rgb_5x5, 5, 300, filter_clamped);
bench_filter_clamped_rgb!(bench_filter_clamped_rgb_7x7, 7, 300, filter_clamped);

bench_filter_clamped_gray!(
bench_filter_clamped_parallel_gray_3x3,
Expand All @@ -1057,6 +1075,24 @@ mod benches {
300,
filter_clamped_parallel
);
bench_filter_clamped_rgb!(
bench_filter_clamped_parallel_rgb_3x3,
3,
300,
filter_clamped_parallel
);
bench_filter_clamped_rgb!(
bench_filter_clamped_parallel_rgb_5x5,
5,
300,
filter_clamped_parallel
);
bench_filter_clamped_rgb!(
bench_filter_clamped_parallel_rgb_7x7,
7,
300,
filter_clamped_parallel
);

/// Baseline implementation of Gaussian blur is that provided by image::imageops.
/// We can also use this to validate correctness of any implementations we add here.
Expand Down

0 comments on commit a41dc3b

Please sign in to comment.