Commit eb18ea7a authored by Luca Barbato's avatar Luca Barbato Committed by Luca Barbato

Use the line iterator in get_sad

70%-90% faster than before according to criterion.
parent a991c689
......@@ -46,28 +46,6 @@ fn bench_get_sad(b: &mut Bencher, bs: &BlockSize) {
b.iter(|| {
let _ = me::get_sad(&mut plane_org, &mut plane_ref, bsw, bsh);
plane_org.y = 0;
plane_ref.y = 0;
})
}
fn bench_get_sad_iter(b: &mut Bencher, bs: &BlockSize) {
let mut ra = ChaChaRng::from_seed([0; 32]);
let bsw = bs.width();
let bsh = bs.height();
let w = 640;
let h = 480;
let input_plane = new_plane(&mut ra, w, h);
let rec_plane = new_plane(&mut ra, w, h);
let po = PlaneOffset { x: 0, y: 0 };
let mut plane_org = input_plane.slice(&po);
let mut plane_ref = rec_plane.slice(&po);
b.iter(|| {
let _ = me::get_sad_iter(&mut plane_org, &mut plane_ref, bsw, bsh);
plane_org.y = 0;
plane_ref.y = 0;
})
}
......@@ -98,6 +76,5 @@ pub fn get_sad(c: &mut Criterion) {
BLOCK_64X16,
];
c.bench_function_over_inputs("get_sad", bench_get_sad, blocks.clone());
c.bench_function_over_inputs("get_sad_iter", bench_get_sad_iter, blocks);
c.bench_function_over_inputs("get_sad", bench_get_sad, blocks);
}
......@@ -22,30 +22,6 @@ pub fn get_sad(
) -> u32 {
let mut sum = 0 as u32;
for _r in 0..blk_h {
{
let slice_org = plane_org.as_slice_w_width(blk_w);
let slice_ref = plane_ref.as_slice_w_width(blk_w);
sum += slice_org
.iter()
.zip(slice_ref)
.map(|(&a, &b)| (a as i32 - b as i32).abs() as u32)
.sum::<u32>();
}
plane_org.y += 1;
plane_ref.y += 1;
}
sum
}
#[inline(always)]
pub fn get_sad_iter(
plane_org: &mut PlaneSlice, plane_ref: &mut PlaneSlice, blk_h: usize,
blk_w: usize
) -> u32 {
let mut sum = 0 as u32;
let org_iter = plane_org.iter_width(blk_w);
let ref_iter = plane_ref.iter_width(blk_w);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment