From 1682ad839a83fe0de554e336cd8e24fcea71482c Mon Sep 17 00:00:00 2001 From: Emil M George Date: Wed, 11 Sep 2024 19:58:10 +0530 Subject: [PATCH] Add image_rs to the flip benchmark --- crates/kornia-imgproc/benches/bench_flip.rs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/crates/kornia-imgproc/benches/bench_flip.rs b/crates/kornia-imgproc/benches/bench_flip.rs index 96a3bc7..b0702f8 100644 --- a/crates/kornia-imgproc/benches/bench_flip.rs +++ b/crates/kornia-imgproc/benches/bench_flip.rs @@ -8,6 +8,21 @@ use rayon::{ slice::{ParallelSlice, ParallelSliceMut}, }; +fn flip_image_crate(image: Image) -> Image { + let image_data = image.as_slice(); + let rgb = image::RgbImage::from_raw( + image.size().width as u32, + image.size().height as u32, + image_data.to_vec(), + ) + .unwrap(); + let image_crate = image::DynamicImage::ImageRgb8(rgb); + + let image_flipped = image_crate.fliph(); + let data = image_flipped.into_rgb8().into_raw(); + Image::new(image.size(), data).unwrap() +} + fn par_par_slicecopy(src: &Image, dst: &mut Image) { dst.as_slice_mut() .par_chunks_exact_mut(src.cols() * 3) @@ -82,6 +97,12 @@ fn bench_flip(c: &mut Criterion) { // output image let output = Image::::from_size_val(image_size, 0.0).unwrap(); + group.bench_with_input( + BenchmarkId::new("image_rs", ¶meter_string), + &image, + |b, i| b.iter(|| black_box(flip_image_crate(i.clone()))), + ); + group.bench_with_input( BenchmarkId::new("par_par_slicecopy", ¶meter_string), &(&image_f32, &output), -- 2.46.0