fimg/benches/overlays.rs

48 lines
1.4 KiB
Rust
Raw Normal View History

2023-09-04 21:55:20 -05:00
#![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];
2023-09-05 23:21:32 -05:00
let mut a: Image<_, 3> = Image::build(64, 64).buf(v.as_mut_slice());
let b: Image<&[u8], 3> = Image::build(4, 4).buf(include_bytes!("3_4x4.imgbuf"));
2023-09-04 21:55:20 -05:00
bench.iter(|| unsafe {
for x in 0..16 {
for y in 0..16 {
a.overlay_at(&b, x * 4, y * 4);
}
}
});
2023-09-05 23:21:32 -05:00
assert_eq!(a.as_ref().buffer(), include_bytes!("3x3_at_out.imgbuf"));
2023-09-04 21:55:20 -05:00
}
#[bench]
fn overlay_4on3at(bench: &mut Bencher) {
let mut a: Image<_, 3> = Image::alloc(64, 64);
2023-09-05 23:21:32 -05:00
let b: Image<&[u8], 4> = Image::build(4, 4).buf(include_bytes!("4_4x4.imgbuf"));
2023-09-04 21:55:20 -05:00
bench.iter(|| unsafe {
for x in 0..16 {
for y in 0..16 {
a.as_mut().overlay_at(&b, x * 4, y * 4);
}
}
});
2023-09-05 23:21:32 -05:00
assert_eq!(a.as_ref().buffer(), include_bytes!("4x3_at_out.imgbuf"));
2023-09-04 21:55:20 -05:00
}
#[bench]
fn overlay_4on4at(bench: &mut Bencher) {
let mut a: Image<_, 4> = Image::alloc(64, 64);
2023-09-05 23:21:32 -05:00
let b: Image<&[u8], 4> = Image::build(4, 4).buf(include_bytes!("4_4x4.imgbuf"));
2023-09-04 21:55:20 -05:00
bench.iter(|| unsafe {
for x in 0..16 {
for y in 0..16 {
a.as_mut().overlay_at(&b, x * 4, y * 4);
}
}
});
2023-09-05 23:21:32 -05:00
assert_eq!(a.as_ref().buffer(), include_bytes!("4x4_at_out.imgbuf"));
2023-09-04 21:55:20 -05:00
}