From dabff333e7a9d89e038b1ce2ede3b31d9aca5d27 Mon Sep 17 00:00:00 2001 From: sebcrozet Date: Sat, 23 Mar 2019 18:15:15 +0100 Subject: [PATCH] Port bidiagonalization benchmark to criterion. --- benches/lib.rs | 2 +- benches/linalg/bidiagonal.rs | 66 +++++++++++++++++++----------------- benches/linalg/mod.rs | 4 ++- 3 files changed, 38 insertions(+), 34 deletions(-) diff --git a/benches/lib.rs b/benches/lib.rs index 7c8cdc70..e500e82c 100644 --- a/benches/lib.rs +++ b/benches/lib.rs @@ -22,4 +22,4 @@ fn reproductible_dmatrix(nrows: usize, ncols: usize) -> DMatrix { DMatrix::::from_fn(nrows, ncols, |_, _| rng.gen()) } -criterion_main!(core::matrix::matrix, core::vector::vector); \ No newline at end of file +criterion_main!(core::matrix::matrix, core::vector::vector, linalg::bidiagonal); \ No newline at end of file diff --git a/benches/linalg/bidiagonal.rs b/benches/linalg/bidiagonal.rs index 9e5a723e..3cb9e666 100644 --- a/benches/linalg/bidiagonal.rs +++ b/benches/linalg/bidiagonal.rs @@ -1,73 +1,75 @@ use na::{Bidiagonal, DMatrix, Matrix4}; -use test::{self, Bencher}; #[path = "../common/macros.rs"] mod macros; // Without unpack. -#[bench] -fn bidiagonalize_100x100(bh: &mut Bencher) { +fn bidiagonalize_100x100(bh: &mut criterion::Criterion) { let m = DMatrix::::new_random(100, 100); - bh.iter(|| test::black_box(Bidiagonal::new(m.clone()))) + bh.bench_function("bidiagonalize_100x100", move |bh| bh.iter(|| test::black_box(Bidiagonal::new(m.clone())))); } -#[bench] -fn bidiagonalize_100x500(bh: &mut Bencher) { +fn bidiagonalize_100x500(bh: &mut criterion::Criterion) { let m = DMatrix::::new_random(100, 500); - bh.iter(|| test::black_box(Bidiagonal::new(m.clone()))) + bh.bench_function("bidiagonalize_100x500", move |bh| bh.iter(|| test::black_box(Bidiagonal::new(m.clone())))); } -#[bench] -fn bidiagonalize_4x4(bh: &mut Bencher) { +fn bidiagonalize_4x4(bh: &mut criterion::Criterion) { let m = Matrix4::::new_random(); - bh.iter(|| test::black_box(Bidiagonal::new(m.clone()))) + bh.bench_function("bidiagonalize_4x4", move |bh| bh.iter(|| test::black_box(Bidiagonal::new(m.clone())))); } -#[bench] -fn bidiagonalize_500x100(bh: &mut Bencher) { +fn bidiagonalize_500x100(bh: &mut criterion::Criterion) { let m = DMatrix::::new_random(500, 100); - bh.iter(|| test::black_box(Bidiagonal::new(m.clone()))) + bh.bench_function("bidiagonalize_500x100", move |bh| bh.iter(|| test::black_box(Bidiagonal::new(m.clone())))); } -#[bench] -fn bidiagonalize_500x500(bh: &mut Bencher) { +fn bidiagonalize_500x500(bh: &mut criterion::Criterion) { let m = DMatrix::::new_random(500, 500); - bh.iter(|| test::black_box(Bidiagonal::new(m.clone()))) + bh.bench_function("bidiagonalize_500x500", move |bh| bh.iter(|| test::black_box(Bidiagonal::new(m.clone())))); } // With unpack. -#[bench] -fn bidiagonalize_unpack_100x100(bh: &mut Bencher) { +fn bidiagonalize_unpack_100x100(bh: &mut criterion::Criterion) { let m = DMatrix::::new_random(100, 100); - bh.iter(|| { + bh.bench_function("bidiagonalize_unpack_100x100", move |bh| bh.iter(|| { let bidiag = Bidiagonal::new(m.clone()); let _ = bidiag.unpack(); - }) + })); } -#[bench] -fn bidiagonalize_unpack_100x500(bh: &mut Bencher) { +fn bidiagonalize_unpack_100x500(bh: &mut criterion::Criterion) { let m = DMatrix::::new_random(100, 500); - bh.iter(|| { + bh.bench_function("bidiagonalize_unpack_100x500", move |bh| bh.iter(|| { let bidiag = Bidiagonal::new(m.clone()); let _ = bidiag.unpack(); - }) + })); } -#[bench] -fn bidiagonalize_unpack_500x100(bh: &mut Bencher) { +fn bidiagonalize_unpack_500x100(bh: &mut criterion::Criterion) { let m = DMatrix::::new_random(500, 100); - bh.iter(|| { + bh.bench_function("bidiagonalize_unpack_500x100", move |bh| bh.iter(|| { let bidiag = Bidiagonal::new(m.clone()); let _ = bidiag.unpack(); - }) + })); } -#[bench] -fn bidiagonalize_unpack_500x500(bh: &mut Bencher) { +fn bidiagonalize_unpack_500x500(bh: &mut criterion::Criterion) { let m = DMatrix::::new_random(500, 500); - bh.iter(|| { + bh.bench_function("bidiagonalize_unpack_500x500", move |bh| bh.iter(|| { let bidiag = Bidiagonal::new(m.clone()); let _ = bidiag.unpack(); - }) + })); } + +criterion_group!(bidiagonal, + bidiagonalize_100x100, + bidiagonalize_100x500, + bidiagonalize_4x4, + bidiagonalize_500x100, + bidiagonalize_500x500, + bidiagonalize_unpack_100x100, + bidiagonalize_unpack_100x500, + bidiagonalize_unpack_500x100, + bidiagonalize_unpack_500x500 +); \ No newline at end of file diff --git a/benches/linalg/mod.rs b/benches/linalg/mod.rs index 526b32ea..fb38835b 100644 --- a/benches/linalg/mod.rs +++ b/benches/linalg/mod.rs @@ -1,3 +1,5 @@ +pub use self::bidiagonal::bidiagonal; + mod bidiagonal; mod cholesky; mod full_piv_lu; @@ -8,4 +10,4 @@ mod schur; mod solve; mod svd; mod symmetric_eigen; -// mod eigen; +// mod eigen; \ No newline at end of file