benchmarks comparing the rust image processing ecosystem
Diffstat (limited to 'benches/resizing.rs')
| -rw-r--r-- | benches/resizing.rs | 57 |
1 files changed, 51 insertions, 6 deletions
diff --git a/benches/resizing.rs b/benches/resizing.rs index fb679ee..18ad709 100644 --- a/benches/resizing.rs +++ b/benches/resizing.rs @@ -1,7 +1,46 @@ +#![feature(array_chunks)] use fimg::Image; +use opencv::{core::CV_8UC3, prelude::*}; + const SIZE: u32 = 5424; const TO: u32 = 2712; +macro_rules! scale_opencv { + ($name:ident => { scale($alg:literal) }) => { + fn $name() { + opencv::core::set_num_threads(1).unwrap(); + let mut data = iai::black_box(include_bytes!("../data.imgbuf").to_vec()) + .array_chunks::<3>() + .flat_map(|&[r, g, b]| [b, g, r]) + .collect::<Vec<_>>(); + let mut o = unsafe { Mat::new_rows_cols(SIZE as i32, SIZE as i32, CV_8UC3).unwrap() }; + opencv::imgproc::resize( + &unsafe { + Mat::new_size_with_data_def( + opencv::core::Size_ { + width: SIZE as i32, + height: SIZE as i32, + }, + CV_8UC3, + data.as_mut_ptr() as *mut core::ffi::c_void, + ) + .unwrap() + }, + &mut o, + opencv::core::Size_ { + width: TO as i32, + height: TO as i32, + }, + 0.0, + 0.0, + $alg, + ) + .unwrap(); + iai::black_box(&o); + } + }; +} + macro_rules! scale_fimg { ($name:ident => { scale($alg: ident) }) => { fn $name() { @@ -56,20 +95,26 @@ macro_rules! scale_img { scale_fimg!(nearest_fimg => { scale(Nearest) }); scale_img!(nearest_img => { scale(Nearest) }); +scale_opencv!(nearest_opencv => { scale(6) }); scale_fimg!(lanczos_fimg => { scale(Lanczos3) }); scale_img!(lanczos_img => { scale(Lanczos3) }); +scale_opencv!(lanczos_opencv => { scale(4) }); scale_resize!(lanczos_resize => { scale(Lanczos3 )}); -scale_fimg!(catmull_fimg => { scale(CatmullRom) }); -scale_img!(catmull_img => { scale(CatmullRom) }); -scale_resize!(catmull_resize => { scale(Catrom) }); +scale_fimg!(bicubic_fimg => { scale(CatmullRom) }); +scale_img!(bicubic_img => { scale(CatmullRom) }); +scale_resize!(bicubic_resize => { scale(Catrom) }); +scale_opencv!(bicubic_opencv => { scale(2) }); iai::main!( nearest_fimg, nearest_img, + nearest_opencv, lanczos_fimg, lanczos_img, lanczos_resize, - catmull_fimg, - catmull_img, - catmull_resize + lanczos_opencv, + bicubic_fimg, + bicubic_img, + bicubic_resize, + bicubic_opencv ); |