Commit 47f37587 authored by Luca Barbato's avatar Luca Barbato Committed by Luca Barbato
Browse files

Move the benchmarks to criterion

parent b451eb83
......@@ -32,7 +32,7 @@ pkg-config = "0.3.12"
bindgen = { version = "0.37", optional = true }
[dev-dependencies]
bencher = "0.1.5"
criterion = "0.2"
[[bin]]
name = "rav1e"
......
......@@ -8,13 +8,13 @@
// PATENTS file, you can obtain it at www.aomedia.org/license/patent.
#[macro_use]
extern crate bencher;
extern crate criterion;
extern crate rand;
extern crate rav1e;
mod predict;
use bencher::*;
use criterion::*;
use rav1e::*;
use rav1e::context::*;
use rav1e::ec;
......@@ -24,31 +24,13 @@ use rav1e::predict::*;
#[cfg(feature = "comparative_bench")]
mod comparative;
struct WriteB {
tx_size: TxSize,
qi: usize
}
impl TDynBenchFn for WriteB {
fn run(&self, b: &mut Bencher) {
write_b_bench(b, self.tx_size, self.qi);
}
}
pub fn write_b() -> Vec<TestDescAndFn> {
use std::borrow::Cow;
let mut benches = ::std::vec::Vec::new();
fn write_b(c: &mut Criterion) {
for &tx_size in &[TxSize::TX_4X4, TxSize::TX_8X8] {
for &qi in &[20, 55] {
let w = WriteB { tx_size, qi };
let n = format!("write_b_bench({:?}, {})", tx_size, qi);
benches.push(TestDescAndFn {
desc: TestDesc { name: Cow::from(n), ignore: false },
testfn: TestFn::DynBenchFn(Box::new(w))
});
c.bench_function(&n, move |b| write_b_bench(b, tx_size, qi));
}
}
benches
}
fn write_b_bench(b: &mut Bencher, tx_size: TxSize, qindex: usize) {
......@@ -108,20 +90,15 @@ fn write_b_bench(b: &mut Bencher, tx_size: TxSize, qindex: usize) {
});
}
benchmark_group!(
criterion_group!(
intra_prediction,
predict::intra_dc_4x4,
predict::intra_h_4x4,
predict::intra_v_4x4,
predict::intra_paeth_4x4,
predict::intra_smooth_4x4,
predict::intra_smooth_h_4x4,
predict::intra_smooth_v_4x4,
predict::intra_cfl_4x4
predict::pred_bench,
);
criterion_group!(write_block, write_b);
#[cfg(feature = "comparative_bench")]
benchmark_main!(comparative::intra_prediction);
criterion_main!(comparative::intra_prediction);
#[cfg(not(feature = "comparative_bench"))]
benchmark_main!(write_b, intra_prediction);
criterion_main!(write_block, intra_prediction);
......@@ -11,22 +11,9 @@ extern crate libc;
mod predict;
benchmark_group!(
use criterion::Criterion;
criterion_group!(
intra_prediction,
predict::intra_dc_4x4_native,
predict::intra_dc_4x4_aom,
predict::intra_h_4x4_native,
predict::intra_h_4x4_aom,
predict::intra_v_4x4_native,
predict::intra_v_4x4_aom,
predict::intra_paeth_4x4_native,
predict::intra_paeth_4x4_aom,
predict::intra_smooth_4x4_native,
predict::intra_smooth_4x4_aom,
predict::intra_smooth_h_4x4_native,
predict::intra_smooth_h_4x4_aom,
predict::intra_smooth_v_4x4_native,
predict::intra_smooth_v_4x4_aom,
predict::intra_cfl_4x4_native,
predict::intra_cfl_4x4_aom
predict::intra_bench,
);
......@@ -7,7 +7,7 @@
// Media Patent License 1.0 was not distributed with this source code in the
// PATENTS file, you can obtain it at www.aomedia.org/license/patent.
use bencher::*;
use criterion::*;
use comparative::libc;
use predict as predict_native;
use predict::*;
......@@ -56,8 +56,8 @@ extern {
}
fn predict_intra_4x4_aom(
b: &mut Bencher,
predictor: unsafe extern "C" fn(*mut u16, libc::ptrdiff_t, libc::c_int, libc::c_int, *const u16, *const u16, libc::c_int))
b: &mut Bencher,
predictor: unsafe extern "C" fn(*mut u16, libc::ptrdiff_t, libc::c_int, libc::c_int, *const u16, *const u16, libc::c_int))
{
let mut rng = ChaChaRng::from_seed([0; 32]);
let (mut block, above_context, left_context) = generate_block(&mut rng);
......@@ -65,71 +65,46 @@ fn predict_intra_4x4_aom(
b.iter(|| {
for _ in 0..MAX_ITER {
unsafe {
predictor(block.as_mut_ptr(), BLOCK_SIZE.width() as libc::ptrdiff_t,
predictor(block.as_mut_ptr(), BLOCK_SIZE.width() as libc::ptrdiff_t,
4, 4, above_context.as_ptr(), left_context.as_ptr(), 8);
}
}
})
}
pub fn intra_dc_4x4_native(b: &mut Bencher) {
predict_native::intra_dc_4x4(b);
}
pub fn intra_dc_4x4_aom(b: &mut Bencher) {
predict_intra_4x4_aom(b, highbd_dc_predictor);
}
pub fn intra_h_4x4_native(b: &mut Bencher) {
predict_native::intra_h_4x4(b);
}
pub fn intra_h_4x4_aom(b: &mut Bencher) {
predict_intra_4x4_aom(b, highbd_h_predictor);
}
pub fn intra_v_4x4_native(b: &mut Bencher) {
predict_native::intra_v_4x4(b);
}
pub fn intra_v_4x4_aom(b: &mut Bencher) {
predict_intra_4x4_aom(b, highbd_v_predictor);
}
pub fn intra_paeth_4x4_native(b: &mut Bencher) {
predict_native::intra_paeth_4x4(b);
}
pub fn intra_paeth_4x4_aom(b: &mut Bencher) {
predict_intra_4x4_aom(b, highbd_paeth_predictor);
}
pub fn intra_smooth_4x4_native(b: &mut Bencher) {
predict_native::intra_smooth_4x4(b);
}
pub fn intra_smooth_4x4_aom(b: &mut Bencher) {
predict_intra_4x4_aom(b, highbd_smooth_predictor);
}
pub fn intra_smooth_h_4x4_native(b: &mut Bencher) {
predict_native::intra_smooth_h_4x4(b);
}
pub fn intra_smooth_h_4x4_aom(b: &mut Bencher) {
predict_intra_4x4_aom(b, highbd_smooth_h_predictor);
}
pub fn intra_smooth_v_4x4_native(b: &mut Bencher) {
predict_native::intra_smooth_v_4x4(b);
}
pub fn intra_smooth_v_4x4_aom(b: &mut Bencher) {
predict_intra_4x4_aom(b, highbd_smooth_v_predictor);
}
pub fn intra_cfl_4x4_native(b: &mut Bencher) {
predict_native::intra_cfl_4x4(b);
pub fn intra_bench(c: &mut Criterion) {
c.bench_functions("intra_dc_4x4", vec![
Fun::new("native", |b, _: &Option<usize>| { predict_native::intra_dc_4x4(b) }),
Fun::new("aom", |b, _: &Option<usize>| { predict_intra_4x4_aom(b, highbd_dc_predictor) })
], None);
c.bench_functions("intra_h_4x4", vec![
Fun::new("native", |b, _: &Option<usize>| { predict_native::intra_h_4x4(b) }),
Fun::new("aom", |b, _: &Option<usize>| { predict_intra_4x4_aom(b, highbd_h_predictor) })
], None);
c.bench_functions("intra_v_4x4", vec![
Fun::new("native", |b, _: &Option<usize>| { predict_native::intra_v_4x4(b) }),
Fun::new("aom", |b, _: &Option<usize>| { predict_intra_4x4_aom(b, highbd_v_predictor) })
], None);
c.bench_functions("intra_paeth_4x4", vec![
Fun::new("native", |b, _: &Option<usize>| { predict_native::intra_paeth_4x4(b) }),
Fun::new("aom", |b, _: &Option<usize>| { predict_intra_4x4_aom(b, highbd_paeth_predictor) })
], None);
c.bench_functions("intra_smooth_4x4", vec![
Fun::new("native", |b, _: &Option<usize>| { predict_native::intra_smooth_4x4(b) }),
Fun::new("aom", |b, _: &Option<usize>| { predict_intra_4x4_aom(b, highbd_smooth_predictor) })
], None);
c.bench_functions("intra_smooth_h_4x4", vec![
Fun::new("native", |b, _: &Option<usize>| { predict_native::intra_smooth_h_4x4(b) }),
Fun::new("aom", |b, _: &Option<usize>| { predict_intra_4x4_aom(b, highbd_smooth_h_predictor) })
], None);
c.bench_functions("intra_smooth_v_4x4", vec![
Fun::new("native", |b, _: &Option<usize>| { predict_native::intra_smooth_v_4x4(b) }),
Fun::new("aom", |b, _: &Option<usize>| { predict_intra_4x4_aom(b, highbd_smooth_v_predictor) })
], None);
c.bench_functions("intra_cfl_4x4", vec![
Fun::new("native", |b, _: &Option<usize>| { predict_native::intra_cfl_4x4(b) }),
Fun::new("aom", |b, _: &Option<usize>| { intra_cfl_4x4_aom(b) })
], None);
}
pub fn intra_cfl_4x4_aom(b: &mut Bencher) {
......
......@@ -7,7 +7,7 @@
// Media Patent License 1.0 was not distributed with this source code in the
// PATENTS file, you can obtain it at www.aomedia.org/license/patent.
use bencher::*;
use criterion::*;
use rand::{ChaChaRng, Rng, SeedableRng};
use rav1e::partition::BlockSize;
use rav1e::predict::{Block4x4, Intra};
......@@ -23,6 +23,17 @@ pub fn generate_block(rng: &mut ChaChaRng) -> (Vec<u16>, Vec<u16>, Vec<u16>) {
(block, above_context, left_context)
}
pub fn pred_bench(c: &mut Criterion) {
c.bench_function("intra_dc_4x4", |b| intra_dc_4x4(b));
c.bench_function("intra_h_4x4", |b| intra_h_4x4(b));
c.bench_function("intra_v_4x4", |b| intra_v_4x4(b));
c.bench_function("intra_paeth_4x4", |b| intra_paeth_4x4(b));
c.bench_function("intra_smooth_4x4", |b| intra_smooth_4x4(b));
c.bench_function("intra_smooth_h_4x4", |b| intra_smooth_h_4x4(b));
c.bench_function("intra_smooth_v_4x4", |b| intra_smooth_v_4x4(b));
c.bench_function("intra_cfl_4x4", |b| intra_cfl_4x4(b));
}
pub fn intra_dc_4x4(b: &mut Bencher) {
let mut ra = ChaChaRng::from_seed([0; 32]);
let (mut block, above, left) = generate_block(&mut ra);
......
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