diff --git a/test_data/3_4x4.imgbuf b/benches/3_4x4.imgbuf similarity index 100% rename from test_data/3_4x4.imgbuf rename to benches/3_4x4.imgbuf diff --git a/test_results/3x3_at_out.buf b/benches/3x3_at_out.imgbuf similarity index 100% rename from test_results/3x3_at_out.buf rename to benches/3x3_at_out.imgbuf diff --git a/test_data/4_180x180.imgbuf b/benches/4_180x180.imgbuf similarity index 100% rename from test_data/4_180x180.imgbuf rename to benches/4_180x180.imgbuf diff --git a/test_data/4_4x4.imgbuf b/benches/4_4x4.imgbuf similarity index 100% rename from test_data/4_4x4.imgbuf rename to benches/4_4x4.imgbuf diff --git a/test_results/4x3_at_out.buf b/benches/4x3_at_out.imgbuf similarity index 100% rename from test_results/4x3_at_out.buf rename to benches/4x3_at_out.imgbuf diff --git a/test_results/4x4_at_out.buf b/benches/4x4_at_out.imgbuf similarity index 100% rename from test_results/4x4_at_out.buf rename to benches/4x4_at_out.imgbuf diff --git a/benches/affine_transformations.rs b/benches/affine_transformations.rs new file mode 100644 index 0000000..ac68d6e --- /dev/null +++ b/benches/affine_transformations.rs @@ -0,0 +1,28 @@ +#![feature(test)] +extern crate test; +use fimg::*; +use test::Bencher; + +macro_rules! bench { + (fn $name: ident() { run $fn: ident() }) => { + #[bench] + fn $name(b: &mut Bencher) { + let mut img: Image<_, 4> = Image::new( + 64.try_into().unwrap(), + 64.try_into().unwrap(), + include_bytes!("4_180x180.imgbuf").to_vec(), + ); + b.iter(|| { + for _ in 0..256 { + img.flip_h(); + } + }); + } + }; +} + +bench!(fn flip_h() { run flip_h() }); +bench!(fn flip_v() { run flip_v() }); +bench!(fn rotate_90() { run rot_90() }); +bench!(fn rotate_180() { run rot_180() }); +bench!(fn rotate_270() { run rot_270() }); diff --git a/benches/overlays.rs b/benches/overlays.rs new file mode 100644 index 0000000..63af444 --- /dev/null +++ b/benches/overlays.rs @@ -0,0 +1,63 @@ +#![feature(test)] +extern crate test; +use fimg::*; +use test::Bencher; + +#[bench] +fn overlay_3on3at(bench: &mut Bencher) { + let mut v = vec![0u8; 3 * 64 * 64]; + let mut a: Image<_, 3> = Image::new( + 64.try_into().unwrap(), + 64.try_into().unwrap(), + v.as_mut_slice(), + ); + let b = Image::<&[u8], 3>::new( + 4.try_into().unwrap(), + 4.try_into().unwrap(), + *&include_bytes!("3_4x4.imgbuf"), + ); + bench.iter(|| unsafe { + for x in 0..16 { + for y in 0..16 { + a.overlay_at(&b, x * 4, y * 4); + } + } + }); + assert_eq!(a.as_ref().buffer, include_bytes!("3x3_at_out.imgbuf")); +} + +#[bench] +fn overlay_4on3at(bench: &mut Bencher) { + let mut a: Image<_, 3> = Image::alloc(64, 64); + let b = Image::<&[u8], 4>::new( + 4.try_into().unwrap(), + 4.try_into().unwrap(), + *&include_bytes!("4_4x4.imgbuf"), + ); + bench.iter(|| unsafe { + for x in 0..16 { + for y in 0..16 { + a.as_mut().overlay_at(&b, x * 4, y * 4); + } + } + }); + assert_eq!(a.as_ref().buffer, include_bytes!("4x3_at_out.imgbuf")); +} + +#[bench] +fn overlay_4on4at(bench: &mut Bencher) { + let mut a: Image<_, 4> = Image::alloc(64, 64); + let b = Image::<&[u8], 4>::new( + 4.try_into().unwrap(), + 4.try_into().unwrap(), + *&include_bytes!("4_4x4.imgbuf"), + ); + bench.iter(|| unsafe { + for x in 0..16 { + for y in 0..16 { + a.as_mut().overlay_at(&b, x * 4, y * 4); + } + } + }); + assert_eq!(a.as_ref().buffer, include_bytes!("4x4_at_out.imgbuf")); +} diff --git a/src/affine.rs b/src/affine.rs index 393b571..91d8e5c 100644 --- a/src/affine.rs +++ b/src/affine.rs @@ -219,35 +219,3 @@ mod tests { ); } } - -#[cfg(test)] -mod bench { - use super::*; - extern crate test; - use crate::Image; - use test::Bencher; - - macro_rules! bench { - (fn $name: ident() { run $fn: ident() }) => { - #[bench] - fn $name(b: &mut Bencher) { - let mut img: Image<_, 4> = Image::new( - 64.try_into().unwrap(), - 64.try_into().unwrap(), - include_bytes!("../test_data/4_180x180.imgbuf").to_vec(), - ); - b.iter(|| { - for _ in 0..256 { - img.flip_h(); - } - }); - } - }; - } - - bench!(fn flip_h() { run flip_h() }); - bench!(fn flip_v() { run flip_v() }); - bench!(fn rotate_90() { run rot_90() }); - bench!(fn rotate_180() { run rot_180() }); - bench!(fn rotate_270() { run rot_270() }); -} diff --git a/src/overlay.rs b/src/overlay.rs index c1cac44..d1211a9 100644 --- a/src/overlay.rs +++ b/src/overlay.rs @@ -170,81 +170,3 @@ impl OverlayAt> for Image<&mut [u8], 4> { self } } - -#[cfg(test)] -mod bench { - extern crate test; - - use test::Bencher; - - use super::*; - use crate::{FromRef, FromRefMut}; - - #[bench] - fn overlay_3on3at(bench: &mut Bencher) { - let mut v = vec![0u8; 3 * 64 * 64]; - let mut a: Image<_, 3> = Image::new( - 64.try_into().unwrap(), - 64.try_into().unwrap(), - v.as_mut_slice(), - ); - let b = Image::<&[u8], 3>::new( - 4.try_into().unwrap(), - 4.try_into().unwrap(), - *&include_bytes!("../test_data/3_4x4.imgbuf"), - ); - bench.iter(|| unsafe { - for x in 0..16 { - for y in 0..16 { - a.overlay_at(&b, x * 4, y * 4); - } - } - }); - assert_eq!( - a.as_ref().buffer, - include_bytes!("../test_results/3x3_at_out.buf") - ); - } - - #[bench] - fn overlay_4on3at(bench: &mut Bencher) { - let mut a: Image<_, 3> = Image::alloc(64, 64); - let b = Image::<&[u8], 4>::new( - 4.try_into().unwrap(), - 4.try_into().unwrap(), - *&include_bytes!("../test_data/4_4x4.imgbuf"), - ); - bench.iter(|| unsafe { - for x in 0..16 { - for y in 0..16 { - a.as_mut().overlay_at(&b, x * 4, y * 4); - } - } - }); - assert_eq!( - a.as_ref().buffer, - include_bytes!("../test_results/4x3_at_out.buf") - ); - } - - #[bench] - fn overlay_4on4at(bench: &mut Bencher) { - let mut a: Image<_, 4> = Image::alloc(64, 64); - let b = Image::<&[u8], 4>::new( - 4.try_into().unwrap(), - 4.try_into().unwrap(), - *&include_bytes!("../test_data/4_4x4.imgbuf"), - ); - bench.iter(|| unsafe { - for x in 0..16 { - for y in 0..16 { - a.as_mut().overlay_at(&b, x * 4, y * 4); - } - } - }); - assert_eq!( - a.as_ref().buffer, - include_bytes!("../test_results/4x4_at_out.buf") - ); - } -}