Commit 9b1f430a authored by Luca Barbato's avatar Luca Barbato
Browse files

Use bencher to stay stable-compatible

parent be88dbcf
......@@ -13,6 +13,11 @@ dependencies = [
"winapi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "bencher"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "bitflags"
version = "0.4.0"
......@@ -108,6 +113,7 @@ dependencies = [
name = "rav1e"
version = "0.1.0"
dependencies = [
"bencher 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
"bitstream-io 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)",
"byteorder 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
"cc 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
......@@ -214,6 +220,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[metadata]
"checksum ansi_term 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6b3568b48b7cefa6b8ce125f9bb4989e52fbcc29ebea88df04cc7c5f12f70455"
"checksum atty 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "8352656fd42c30a0c3c89d26dea01e3b77c0ab2af18230835c15e2e13cd51859"
"checksum bencher 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "7dfdb4953a096c551ce9ace855a604d702e6e62d77fac690575ae347571717f5"
"checksum bitflags 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8dead7461c1127cf637931a1e50934eb6eee8bff2f74433ac7909e9afcee04a3"
"checksum bitflags 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b3c30d3802dfb7281680d6285f2ccdaa8c2d8fee41f93805dba5c4cf50dc23cf"
"checksum bitstream-io 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)" = "48f26d7f042e5a120b0956c7546bbb971151f6e6e895b3f5d141ecbd17c90d67"
......
......@@ -16,3 +16,10 @@ y4m = "0.1"
[build-dependencies]
cc = "1"
[dev-dependencies]
bencher = "0.1.5"
[[bench]]
name = "predict"
harness = false
#[macro_use]
extern crate bencher;
extern crate rav1e;
extern crate rand;
extern crate libc;
use bencher::Bencher;
use rand::{ChaChaRng, Rng};
use rav1e::predict::*;
extern {
fn highbd_dc_predictor(dst: *mut u16, stride: libc::ptrdiff_t, bw: libc::c_int,
bh: libc::c_int, above: *const u16,
left: *const u16, bd: libc::c_int);
fn highbd_dc_left_predictor(dst: *mut u16, stride: libc::ptrdiff_t, bw: libc::c_int,
bh: libc::c_int, above: *const u16,
left: *const u16, bd: libc::c_int);
fn highbd_dc_top_predictor(dst: *mut u16, stride: libc::ptrdiff_t, bw: libc::c_int,
bh: libc::c_int, above: *const u16,
left: *const u16, bd: libc::c_int);
fn highbd_h_predictor(dst: *mut u16, stride: libc::ptrdiff_t, bw: libc::c_int,
bh: libc::c_int, above: *const u16,
left: *const u16, bd: libc::c_int);
fn highbd_v_predictor(dst: *mut u16, stride: libc::ptrdiff_t, bw: libc::c_int,
bh: libc::c_int, above: *const u16,
left: *const u16, bd: libc::c_int);
}
#[inline(always)]
fn pred_dc_4x4(output: &mut [u16], stride: usize, above: &[u16], left: &[u16]) {
unsafe {
highbd_dc_predictor(output.as_mut_ptr(), stride as libc::ptrdiff_t, 4, 4, above.as_ptr(), left.as_ptr(), 8);
}
}
#[inline(always)]
fn pred_h_4x4(output: &mut [u16], stride: usize, above: &[u16], left: &[u16]) {
unsafe {
highbd_h_predictor(output.as_mut_ptr(), stride as libc::ptrdiff_t, 4, 4, above.as_ptr(), left.as_ptr(), 8);
}
}
#[inline(always)]
fn pred_v_4x4(output: &mut [u16], stride: usize, above: &[u16], left: &[u16]) {
unsafe {
highbd_v_predictor(output.as_mut_ptr(), stride as libc::ptrdiff_t, 4, 4, above.as_ptr(), left.as_ptr(), 8);
}
}
const MAX_ITER: usize = 50000;
fn setup_pred(ra: &mut ChaChaRng) -> (Vec<u16>, Vec<u16>, Vec<u16>) {
let o1 = vec![0u16; 32 * 32];
let above: Vec<u16> = (0..32).map(|_| ra.gen()).collect();
let left: Vec<u16> = (0..32).map(|_| ra.gen()).collect();
(above, left, o1)
}
fn native(b: &mut Bencher) {
let mut ra = ChaChaRng::new_unseeded();
let (above, left, mut o2) = setup_pred(&mut ra);
b.iter(|| {
for _ in 0..MAX_ITER {
pred_dc(&mut o2, 32, &above[..4], &left[..4]);
}
})
}
fn native_trait(b: &mut Bencher) {
let mut ra = ChaChaRng::new_unseeded();
let (above, left, mut o2) = setup_pred(&mut ra);
b.iter(|| {
for _ in 0..MAX_ITER {
pred_dc_trait::<Block4x4>(&mut o2, 32, &above[..4], &left[..4]);
}
})
}
fn aom(b: &mut Bencher) {
let mut ra = ChaChaRng::new_unseeded();
let (above, left, mut o2) = setup_pred(&mut ra);
b.iter(|| {
for _ in 0..MAX_ITER {
pred_dc_4x4(&mut o2, 32, &above[..4], &left[..4]);
}
})
}
benchmark_group!(predict, aom, native_trait, native);
benchmark_main!(predict);
#![allow(safe_extern_statics)]
#![feature(test)]
extern crate test;
extern crate bitstream_io;
extern crate byteorder;
extern crate clap;
......@@ -15,13 +13,14 @@ use bitstream_io::{BE, BitWriter};
use byteorder::*;
use clap::{App, Arg};
mod ec;
mod partition;
mod context;
mod transform;
mod quantize;
mod predict;
mod rdo;
// for benchmarking purpose
pub mod ec;
pub mod partition;
pub mod context;
pub mod transform;
pub mod quantize;
pub mod predict;
pub mod rdo;
use context::*;
use partition::*;
......
......@@ -99,10 +99,9 @@ pub fn pred_v(output: &mut [u16], stride: usize, above: &[u16], bh: usize) {
}
#[cfg(test)]
mod test {
pub mod test {
use super::*;
use rand::{ChaChaRng, Rng};
use test::Bencher;
const MAX_ITER: usize = 50000;
......@@ -227,41 +226,4 @@ mod test {
}
}
}
#[bench]
fn native(b: &mut Bencher) {
let mut ra = ChaChaRng::new_unseeded();
let (above, left, _, mut o2) = setup_pred(&mut ra);
b.iter(|| {
for _ in 0..MAX_ITER {
pred_dc(&mut o2, 32, &above[..4], &left[..4]);
}
})
}
#[bench]
fn native_trait(b: &mut Bencher) {
let mut ra = ChaChaRng::new_unseeded();
let (above, left, _, mut o2) = setup_pred(&mut ra);
b.iter(|| {
for _ in 0..MAX_ITER {
pred_dc_trait::<Block4x4>(&mut o2, 32, &above[..4], &left[..4]);
}
})
}
#[bench]
fn aom(b: &mut Bencher) {
let mut ra = ChaChaRng::new_unseeded();
let (above, left, _, mut o2) = setup_pred(&mut ra);
b.iter(|| {
for _ in 0..MAX_ITER {
pred_dc_4x4(&mut o2, 32, &above[..4], &left[..4]);
}
})
}
}
Supports Markdown
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