| 1 |
#[macro_use] |
| 2 |
extern crate criterion; |
| 3 |
|
| 4 |
extern crate transpose; |
| 5 |
|
| 6 |
use criterion::{Criterion, ParameterizedBenchmark, Throughput}; |
| 7 |
use std::mem; |
| 8 |
use std::time::Duration; |
| 9 |
|
| 10 |
fn bench_oop_transpose<T: Copy + Default>(c: &mut Criterion, tyname: &str) { |
| 11 |
let ref sizes = [(4, 4), (8, 8), (16, 16), (64, 64), (256, 256), (1024, 1024), (2048, 2048), (4096, 4096)]; |
| 12 |
|
| 13 |
let bench = ParameterizedBenchmark::new(tyname, |
| 14 |
|b, &&(width, height)| { |
| 15 |
let mut buffer = vec![T::default(); width * height]; |
| 16 |
let mut scratch = vec![T::default(); width * height]; |
| 17 |
|
| 18 |
b.iter(|| { transpose::transpose(&mut buffer, &mut scratch, width, height); }); |
| 19 |
}, |
| 20 |
sizes) |
| 21 |
.throughput(|&&(width, height)| Throughput::Bytes((width * height * mem::size_of::<T>()) as u32)) |
| 22 |
.warm_up_time(Duration::from_secs(1)); |
| 23 |
|
| 24 |
c.bench("square transposes out-of-place", bench); |
| 25 |
} |
| 26 |
|
| 27 |
fn bench_oop_u32(c: &mut Criterion) { bench_oop_transpose::<u32>(c, "u32") } |
| 28 |
fn bench_oop_u64(c: &mut Criterion) { bench_oop_transpose::<u64>(c, "u64") } |
| 29 |
|
| 30 |
criterion_group!(out_of_place_benches, bench_oop_u32, bench_oop_u64); |
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
fn bench_inplace_transpose<T: Copy + Default>(c: &mut Criterion, tyname: &str) { |
| 37 |
let ref sizes = [(4, 4), (8, 8), (16, 16), (64, 64), (256, 256), (1024, 1024)]; |
| 38 |
|
| 39 |
let bench = ParameterizedBenchmark::new(tyname, |
| 40 |
|b, &&(width, height)| { |
| 41 |
let mut buffer = vec![T::default(); width * height]; |
| 42 |
let mut scratch = vec![T::default(); std::cmp::max(width, height)]; |
| 43 |
|
| 44 |
b.iter(|| { transpose::transpose_inplace(&mut buffer, &mut scratch, width, height); }); |
| 45 |
}, |
| 46 |
sizes) |
| 47 |
.throughput(|&&(width, height)| Throughput::Bytes((width * height * mem::size_of::<T>()) as u32)) |
| 48 |
.warm_up_time(Duration::from_secs(1)); |
| 49 |
|
| 50 |
c.bench("square transposes inplace", bench); |
| 51 |
} |
| 52 |
|
| 53 |
fn bench_inplace_u32(c: &mut Criterion) { bench_inplace_transpose::<u32>(c, "u32") } |
| 54 |
fn bench_inplace_u64(c: &mut Criterion) { bench_inplace_transpose::<u64>(c, "u64") } |
| 55 |
|
| 56 |
criterion_group!(inplace_benches, bench_inplace_u32, bench_inplace_u64); |
| 57 |
|
| 58 |
criterion_main!(out_of_place_benches, inplace_benches); |