From 1e60bc822ba20c417dc54ecb9b5a539a33291e12 Mon Sep 17 00:00:00 2001 From: sebcrozet Date: Sat, 23 Mar 2019 19:07:16 +0100 Subject: [PATCH] Port all remaining benchmarks to criterion. --- benches/core/matrix.rs | 166 ++++++++++++++++++------------ benches/core/mod.rs | 7 +- benches/core/vector.rs | 62 +++++++++-- benches/geometry/mod.rs | 2 + benches/geometry/quaternion.rs | 12 ++- benches/lib.rs | 16 ++- benches/linalg/bidiagonal.rs | 4 +- benches/linalg/cholesky.rs | 81 ++++++++------- benches/linalg/eigen.rs | 27 ++--- benches/linalg/full_piv_lu.rs | 83 ++++++++------- benches/linalg/hessenberg.rs | 52 +++++----- benches/linalg/lu.rs | 80 +++++++------- benches/linalg/mod.rs | 9 ++ benches/linalg/qr.rs | 109 ++++++++++---------- benches/linalg/schur.rs | 52 +++++----- benches/linalg/solve.rs | 69 +++++++------ benches/linalg/svd.rs | 101 +++++++++--------- benches/linalg/symmetric_eigen.rs | 28 ++--- 18 files changed, 555 insertions(+), 405 deletions(-) diff --git a/benches/core/matrix.rs b/benches/core/matrix.rs index 896f2c97..12fb836d 100644 --- a/benches/core/matrix.rs +++ b/benches/core/matrix.rs @@ -1,7 +1,6 @@ use na::{DMatrix, DVector, Matrix2, Matrix3, Matrix4, MatrixN, Vector2, Vector3, Vector4, U10}; use rand::{IsaacRng, Rng}; use std::ops::{Add, Div, Mul, Sub}; -use test::{self, Bencher}; #[path = "../common/macros.rs"] mod macros; @@ -46,155 +45,196 @@ bench_unop!(mat2_transpose, Matrix2, transpose); bench_unop!(mat3_transpose, Matrix3, transpose); bench_unop!(mat4_transpose, Matrix4, transpose); -#[bench] -fn mat_div_scalar(b: &mut Bencher) { +fn mat_div_scalar(b: &mut criterion::Criterion) { let a = DMatrix::from_row_slice(1000, 1000, &vec![2.0; 1000000]); let n = 42.0; - b.iter(|| { + b.bench_function("mat_div_scalar", move |bh| bh.iter(|| { let mut aa = a.clone(); let mut b = aa.slice_mut((0, 0), (1000, 1000)); b /= n - }) + })); } -#[bench] -fn mat100_add_mat100(bench: &mut Bencher) { +fn mat100_add_mat100(bench: &mut criterion::Criterion) { let a = DMatrix::::new_random(100, 100); let b = DMatrix::::new_random(100, 100); - bench.iter(|| &a + &b) + bench.bench_function("mat100_add_mat100", move |bh| bh.iter(|| &a + &b)); } -#[bench] -fn mat4_mul_mat4(bench: &mut Bencher) { +fn mat4_mul_mat4(bench: &mut criterion::Criterion) { let a = DMatrix::::new_random(4, 4); let b = DMatrix::::new_random(4, 4); - bench.iter(|| &a * &b) + bench.bench_function("mat4_mul_mat4", move |bh| bh.iter(|| &a * &b)); } -#[bench] -fn mat5_mul_mat5(bench: &mut Bencher) { +fn mat5_mul_mat5(bench: &mut criterion::Criterion) { let a = DMatrix::::new_random(5, 5); let b = DMatrix::::new_random(5, 5); - bench.iter(|| &a * &b) + bench.bench_function("mat5_mul_mat5", move |bh| bh.iter(|| &a * &b)); } -#[bench] -fn mat6_mul_mat6(bench: &mut Bencher) { +fn mat6_mul_mat6(bench: &mut criterion::Criterion) { let a = DMatrix::::new_random(6, 6); let b = DMatrix::::new_random(6, 6); - bench.iter(|| &a * &b) + bench.bench_function("mat6_mul_mat6", move |bh| bh.iter(|| &a * &b)); } -#[bench] -fn mat7_mul_mat7(bench: &mut Bencher) { +fn mat7_mul_mat7(bench: &mut criterion::Criterion) { let a = DMatrix::::new_random(7, 7); let b = DMatrix::::new_random(7, 7); - bench.iter(|| &a * &b) + bench.bench_function("mat7_mul_mat7", move |bh| bh.iter(|| &a * &b)); } -#[bench] -fn mat8_mul_mat8(bench: &mut Bencher) { +fn mat8_mul_mat8(bench: &mut criterion::Criterion) { let a = DMatrix::::new_random(8, 8); let b = DMatrix::::new_random(8, 8); - bench.iter(|| &a * &b) + bench.bench_function("mat8_mul_mat8", move |bh| bh.iter(|| &a * &b)); } -#[bench] -fn mat9_mul_mat9(bench: &mut Bencher) { +fn mat9_mul_mat9(bench: &mut criterion::Criterion) { let a = DMatrix::::new_random(9, 9); let b = DMatrix::::new_random(9, 9); - bench.iter(|| &a * &b) + bench.bench_function("mat9_mul_mat9", move |bh| bh.iter(|| &a * &b)); } -#[bench] -fn mat10_mul_mat10(bench: &mut Bencher) { +fn mat10_mul_mat10(bench: &mut criterion::Criterion) { let a = DMatrix::::new_random(10, 10); let b = DMatrix::::new_random(10, 10); - bench.iter(|| &a * &b) + bench.bench_function("mat10_mul_mat10", move |bh| bh.iter(|| &a * &b)); } -#[bench] -fn mat10_mul_mat10_static(bench: &mut Bencher) { +fn mat10_mul_mat10_static(bench: &mut criterion::Criterion) { let a = MatrixN::::new_random(); let b = MatrixN::::new_random(); - bench.iter(|| &a * &b) + bench.bench_function("mat10_mul_mat10_static", move |bh| bh.iter(|| &a * &b)); } -#[bench] -fn mat100_mul_mat100(bench: &mut Bencher) { +fn mat100_mul_mat100(bench: &mut criterion::Criterion) { let a = DMatrix::::new_random(100, 100); let b = DMatrix::::new_random(100, 100); - bench.iter(|| &a * &b) + bench.bench_function("mat100_mul_mat100", move |bh| bh.iter(|| &a * &b)); } -#[bench] -fn mat500_mul_mat500(bench: &mut Bencher) { +fn mat500_mul_mat500(bench: &mut criterion::Criterion) { let a = DMatrix::::from_element(500, 500, 5f64); let b = DMatrix::::from_element(500, 500, 6f64); - bench.iter(|| &a * &b) + bench.bench_function("mat500_mul_mat500", move |bh| bh.iter(|| &a * &b)); } -#[bench] -fn copy_from(bench: &mut Bencher) { +fn copy_from(bench: &mut criterion::Criterion) { let a = DMatrix::::new_random(1000, 1000); let mut b = DMatrix::::new_random(1000, 1000); - bench.iter(|| { - b.copy_from(&a); - }) + bench.bench_function("copy_from", move |bh| bh.iter(|| { + b.copy_from(&a); + })); } -#[bench] -fn axpy(bench: &mut Bencher) { +fn axpy(bench: &mut criterion::Criterion) { let x = DVector::::from_element(100000, 2.0); let mut y = DVector::::from_element(100000, 3.0); let a = 42.0; - bench.iter(|| { - y.axpy(a, &x, 1.0); - }) + bench.bench_function("axpy", move |bh| bh.iter(|| { + y.axpy(a, &x, 1.0); + })); } -#[bench] -fn tr_mul_to(bench: &mut Bencher) { +fn tr_mul_to(bench: &mut criterion::Criterion) { let a = DMatrix::::new_random(1000, 1000); let b = DVector::::new_random(1000); let mut c = DVector::from_element(1000, 0.0); - bench.iter(|| a.tr_mul_to(&b, &mut c)) + bench.bench_function("", move |bh| bh.iter(|| a.tr_mul_to(&b, &mut c))); } -#[bench] -fn mat_mul_mat(bench: &mut Bencher) { +fn mat_mul_mat(bench: &mut criterion::Criterion) { let a = DMatrix::::new_random(100, 100); let b = DMatrix::::new_random(100, 100); let mut ab = DMatrix::::from_element(100, 100, 0.0); - bench.iter(|| { - test::black_box(a.mul_to(&b, &mut ab)); - }) + bench.bench_function("mat_mul_mat", move |bh| bh.iter(|| { + test::black_box(a.mul_to(&b, &mut ab)); + })); } -#[bench] -fn mat100_from_fn(bench: &mut Bencher) { - bench.iter(|| DMatrix::from_fn(100, 100, |a, b| a + b)) +fn mat100_from_fn(bench: &mut criterion::Criterion) { + bench.bench_function("mat100_from_fn", move |bh| bh.iter(|| DMatrix::from_fn(100, 100, |a, b| a + b))); } -#[bench] -fn mat500_from_fn(bench: &mut Bencher) { - bench.iter(|| DMatrix::from_fn(500, 500, |a, b| a + b)) +fn mat500_from_fn(bench: &mut criterion::Criterion) { + bench.bench_function("mat500_from_fn", move |bh| bh.iter(|| DMatrix::from_fn(500, 500, |a, b| a + b))); } -criterion_group!(matrix, mat2_transpose); \ No newline at end of file +criterion_group!(matrix, + mat2_mul_m, + mat3_mul_m, + mat4_mul_m, + + mat2_tr_mul_m, + mat3_tr_mul_m, + mat4_tr_mul_m, + + mat2_add_m, + mat3_add_m, + mat4_add_m, + + mat2_sub_m, + mat3_sub_m, + mat4_sub_m, + + mat2_mul_v, + mat3_mul_v, + mat4_mul_v, + + mat2_tr_mul_v, + mat3_tr_mul_v, + mat4_tr_mul_v, + + mat2_mul_s, + mat3_mul_s, + mat4_mul_s, + + mat2_div_s, + mat3_div_s, + mat4_div_s, + + mat2_inv, + mat3_inv, + mat4_inv, + + mat2_transpose, + mat3_transpose, + mat4_transpose, + + mat_div_scalar, + mat100_add_mat100, + mat4_mul_mat4, + mat5_mul_mat5, + mat6_mul_mat6, + mat7_mul_mat7, + mat8_mul_mat8, + mat9_mul_mat9, + mat10_mul_mat10, + mat10_mul_mat10_static, + mat100_mul_mat100, + mat500_mul_mat500, + copy_from, + axpy, + tr_mul_to, + mat_mul_mat, + mat100_from_fn, + mat500_from_fn, +); \ No newline at end of file diff --git a/benches/core/mod.rs b/benches/core/mod.rs index f3e633a8..eda9ddaa 100644 --- a/benches/core/mod.rs +++ b/benches/core/mod.rs @@ -1,2 +1,5 @@ -pub mod matrix; -pub mod vector; +pub use self::matrix::matrix; +pub use self::vector::vector; + +mod matrix; +mod vector; diff --git a/benches/core/vector.rs b/benches/core/vector.rs index 814f50e7..7d3237e8 100644 --- a/benches/core/vector.rs +++ b/benches/core/vector.rs @@ -54,7 +54,7 @@ fn vec10000_axpy_f64(bh: &mut criterion::Criterion) { let b = DVector::new_random(10000); let n = rng.gen::(); - bh.bench_function("", move |bh| bh.iter(|| a.axpy(n, &b, 1.0))); + bh.bench_function("vec10000_axpy_f64", move |bh| bh.iter(|| a.axpy(n, &b, 1.0))); } fn vec10000_axpy_beta_f64(bh: &mut criterion::Criterion) { @@ -65,7 +65,7 @@ fn vec10000_axpy_beta_f64(bh: &mut criterion::Criterion) { let n = rng.gen::(); let beta = rng.gen::(); - bh.bench_function("", move |bh| bh.iter(|| a.axpy(n, &b, beta))); + bh.bench_function("vec10000_axpy_beta_f64", move |bh| bh.iter(|| a.axpy(n, &b, beta))); } fn vec10000_axpy_f64_slice(bh: &mut criterion::Criterion) { @@ -75,7 +75,7 @@ fn vec10000_axpy_f64_slice(bh: &mut criterion::Criterion) { let b = DVector::new_random(10000); let n = rng.gen::(); - bh.bench_function("", move |bh| bh.iter(|| { + bh.bench_function("vec10000_axpy_f64_slice", move |bh| bh.iter(|| { let mut a = a.fixed_rows_mut::(0); let b = b.fixed_rows::(0); @@ -91,7 +91,7 @@ fn vec10000_axpy_f64_static(bh: &mut criterion::Criterion) { let n = rng.gen::(); // NOTE: for some reasons, it is much faster if the arument are boxed (Box::new(VectorN...)). - bh.bench_function("", move |bh| bh.iter(|| a.axpy(n, &b, 1.0))); + bh.bench_function("vec10000_axpy_f64_static", move |bh| bh.iter(|| a.axpy(n, &b, 1.0))); } fn vec10000_axpy_f32(bh: &mut criterion::Criterion) { @@ -101,7 +101,7 @@ fn vec10000_axpy_f32(bh: &mut criterion::Criterion) { let b = DVector::new_random(10000); let n = rng.gen::(); - bh.bench_function("", move |bh| bh.iter(|| a.axpy(n, &b, 1.0))); + bh.bench_function("vec10000_axpy_f32", move |bh| bh.iter(|| a.axpy(n, &b, 1.0))); } fn vec10000_axpy_beta_f32(bh: &mut criterion::Criterion) { @@ -112,7 +112,55 @@ fn vec10000_axpy_beta_f32(bh: &mut criterion::Criterion) { let n = rng.gen::(); let beta = rng.gen::(); - bh.bench_function("", move |bh| bh.iter(|| a.axpy(n, &b, beta))); + bh.bench_function("vec10000_axpy_beta_f32", move |bh| bh.iter(|| a.axpy(n, &b, beta))); } -criterion_group!(vector, vec10000_axpy_f64_static); +criterion_group!(vector, + vec2_add_v_f32, + vec3_add_v_f32, + vec4_add_v_f32, + + vec2_add_v_f64, + vec3_add_v_f64, + vec4_add_v_f64, + + vec2_sub_v, + vec3_sub_v, + vec4_sub_v, + + vec2_mul_s, + vec3_mul_s, + vec4_mul_s, + + vec2_div_s, + vec3_div_s, + vec4_div_s, + + vec2_dot_f32, + vec3_dot_f32, + vec4_dot_f32, + + vec2_dot_f64, + vec3_dot_f64, + vec4_dot_f64, + + vec3_cross, + + vec2_norm, + vec3_norm, + vec4_norm, + + vec2_normalize, + vec3_normalize, + vec4_normalize, + + vec10000_dot_f64, + vec10000_dot_f32, + + vec10000_axpy_f64, + vec10000_axpy_beta_f64, + vec10000_axpy_f64_slice, + vec10000_axpy_f64_static, + vec10000_axpy_f32, + vec10000_axpy_beta_f32 +); diff --git a/benches/geometry/mod.rs b/benches/geometry/mod.rs index 0f9eb371..d0d0e948 100644 --- a/benches/geometry/mod.rs +++ b/benches/geometry/mod.rs @@ -1 +1,3 @@ +pub use quaternion::quaternion; + mod quaternion; diff --git a/benches/geometry/quaternion.rs b/benches/geometry/quaternion.rs index bc94c054..dd079aac 100644 --- a/benches/geometry/quaternion.rs +++ b/benches/geometry/quaternion.rs @@ -1,7 +1,6 @@ use na::{Quaternion, UnitQuaternion, Vector3}; use rand::{IsaacRng, Rng}; use std::ops::{Add, Div, Mul, Sub}; -use test::{self, Bencher}; #[path = "../common/macros.rs"] mod macros; @@ -25,3 +24,14 @@ bench_unop!(unit_quaternion_inv, UnitQuaternion, inverse); // bench_unop_self!(quaternion_conjugate, Quaternion, conjugate); // bench_unop!(quaternion_normalize, Quaternion, normalize); + +criterion_group!(quaternion, + quaternion_add_q, + quaternion_sub_q, + quaternion_mul_q, + unit_quaternion_mul_v, + quaternion_mul_s, + quaternion_div_s, + quaternion_inv, + unit_quaternion_inv +); \ No newline at end of file diff --git a/benches/lib.rs b/benches/lib.rs index e500e82c..d5333542 100644 --- a/benches/lib.rs +++ b/benches/lib.rs @@ -22,4 +22,18 @@ fn reproductible_dmatrix(nrows: usize, ncols: usize) -> DMatrix { DMatrix::::from_fn(nrows, ncols, |_, _| rng.gen()) } -criterion_main!(core::matrix::matrix, core::vector::vector, linalg::bidiagonal); \ No newline at end of file +criterion_main!( + core::matrix, + core::vector, + geometry::quaternion, + linalg::bidiagonal, + linalg::cholesky, + linalg::full_piv_lu, + linalg::hessenberg, + linalg::lu, + linalg::qr, + linalg::schur, + linalg::solve, + linalg::svd, + linalg::symmetric_eigen, +); \ No newline at end of file diff --git a/benches/linalg/bidiagonal.rs b/benches/linalg/bidiagonal.rs index 3cb9e666..ed126205 100644 --- a/benches/linalg/bidiagonal.rs +++ b/benches/linalg/bidiagonal.rs @@ -67,9 +67,9 @@ criterion_group!(bidiagonal, bidiagonalize_100x500, bidiagonalize_4x4, bidiagonalize_500x100, - bidiagonalize_500x500, +// bidiagonalize_500x500, // too long bidiagonalize_unpack_100x100, bidiagonalize_unpack_100x500, bidiagonalize_unpack_500x100, - bidiagonalize_unpack_500x500 +// bidiagonalize_unpack_500x500 // too long ); \ No newline at end of file diff --git a/benches/linalg/cholesky.rs b/benches/linalg/cholesky.rs index 73c028cb..40ca9821 100644 --- a/benches/linalg/cholesky.rs +++ b/benches/linalg/cholesky.rs @@ -1,109 +1,112 @@ use na::{Cholesky, DMatrix, DVector}; -use test::{self, Bencher}; -#[bench] -fn cholesky_100x100(bh: &mut Bencher) { +fn cholesky_100x100(bh: &mut criterion::Criterion) { let m = DMatrix::::new_random(100, 100); let m = &m * m.transpose(); - bh.iter(|| test::black_box(Cholesky::new(m.clone()))) + bh.bench_function("cholesky_100x100", move |bh| bh.iter(|| test::black_box(Cholesky::new(m.clone())))); } -#[bench] -fn cholesky_500x500(bh: &mut Bencher) { +fn cholesky_500x500(bh: &mut criterion::Criterion) { let m = DMatrix::::new_random(500, 500); let m = &m * m.transpose(); - bh.iter(|| test::black_box(Cholesky::new(m.clone()))) + bh.bench_function("cholesky_500x500", move |bh| bh.iter(|| test::black_box(Cholesky::new(m.clone())))); } // With unpack. -#[bench] -fn cholesky_decompose_unpack_100x100(bh: &mut Bencher) { +fn cholesky_decompose_unpack_100x100(bh: &mut criterion::Criterion) { let m = DMatrix::::new_random(100, 100); let m = &m * m.transpose(); - bh.iter(|| { + bh.bench_function("cholesky_decompose_unpack_100x100", move |bh| bh.iter(|| { let chol = Cholesky::new(m.clone()).unwrap(); let _ = chol.unpack(); - }) + })); } -#[bench] -fn cholesky_decompose_unpack_500x500(bh: &mut Bencher) { +fn cholesky_decompose_unpack_500x500(bh: &mut criterion::Criterion) { let m = DMatrix::::new_random(500, 500); let m = &m * m.transpose(); - bh.iter(|| { + bh.bench_function("cholesky_decompose_unpack_500x500", move |bh| bh.iter(|| { let chol = Cholesky::new(m.clone()).unwrap(); let _ = chol.unpack(); - }) + })); } -#[bench] -fn cholesky_solve_10x10(bh: &mut Bencher) { +fn cholesky_solve_10x10(bh: &mut criterion::Criterion) { let m = DMatrix::::new_random(10, 10); let m = &m * m.transpose(); let v = DVector::::new_random(10); let chol = Cholesky::new(m.clone()).unwrap(); - bh.iter(|| { + bh.bench_function("cholesky_solve_10x10", move |bh| bh.iter(|| { let _ = chol.solve(&v); - }) + })); } -#[bench] -fn cholesky_solve_100x100(bh: &mut Bencher) { +fn cholesky_solve_100x100(bh: &mut criterion::Criterion) { let m = DMatrix::::new_random(100, 100); let m = &m * m.transpose(); let v = DVector::::new_random(100); let chol = Cholesky::new(m.clone()).unwrap(); - bh.iter(|| { + bh.bench_function("cholesky_solve_100x100", move |bh| bh.iter(|| { let _ = chol.solve(&v); - }) + })); } -#[bench] -fn cholesky_solve_500x500(bh: &mut Bencher) { +fn cholesky_solve_500x500(bh: &mut criterion::Criterion) { let m = DMatrix::::new_random(500, 500); let m = &m * m.transpose(); let v = DVector::::new_random(500); let chol = Cholesky::new(m.clone()).unwrap(); - bh.iter(|| { + bh.bench_function("cholesky_solve_500x500", move |bh| bh.iter(|| { let _ = chol.solve(&v); - }) + })); } -#[bench] -fn cholesky_inverse_10x10(bh: &mut Bencher) { + +fn cholesky_inverse_10x10(bh: &mut criterion::Criterion) { let m = DMatrix::::new_random(10, 10); let m = &m * m.transpose(); let chol = Cholesky::new(m.clone()).unwrap(); - bh.iter(|| { + bh.bench_function("cholesky_inverse_10x10", move |bh| bh.iter(|| { let _ = chol.inverse(); - }) + })); } -#[bench] -fn cholesky_inverse_100x100(bh: &mut Bencher) { +fn cholesky_inverse_100x100(bh: &mut criterion::Criterion) { let m = DMatrix::::new_random(100, 100); let m = &m * m.transpose(); let chol = Cholesky::new(m.clone()).unwrap(); - bh.iter(|| { + bh.bench_function("cholesky_inverse_100x100", move |bh| bh.iter(|| { let _ = chol.inverse(); - }) + })); } -#[bench] -fn cholesky_inverse_500x500(bh: &mut Bencher) { +fn cholesky_inverse_500x500(bh: &mut criterion::Criterion) { let m = DMatrix::::new_random(500, 500); let m = &m * m.transpose(); let chol = Cholesky::new(m.clone()).unwrap(); - bh.iter(|| { + bh.bench_function("cholesky_inverse_500x500", move |bh| bh.iter(|| { let _ = chol.inverse(); - }) + })); } + +criterion_group!(cholesky, + cholesky_100x100, + cholesky_500x500, + cholesky_decompose_unpack_100x100, + cholesky_decompose_unpack_500x500, + cholesky_solve_10x10, + cholesky_solve_100x100, + cholesky_solve_500x500, + cholesky_inverse_10x10, + cholesky_inverse_100x100, + cholesky_inverse_500x500 +); \ No newline at end of file diff --git a/benches/linalg/eigen.rs b/benches/linalg/eigen.rs index 54aa77a5..0b1e6b26 100644 --- a/benches/linalg/eigen.rs +++ b/benches/linalg/eigen.rs @@ -1,30 +1,33 @@ use test::Bencher; use na::{DMatrix, Eigen}; -#[bench] -fn eigen_100x100(bh: &mut Bencher) { +fn eigen_100x100(bh: &mut criterion::Criterion) { let m = DMatrix::::new_random(100, 100); - bh.iter(|| Eigen::new(m.clone(), 1.0e-7, 0)) + bh.bench_function("eigen_100x100", move |bh| bh.iter(|| Eigen::new(m.clone(), 1.0e-7, 0))); } -#[bench] -fn eigen_500x500(bh: &mut Bencher) { +fn eigen_500x500(bh: &mut criterion::Criterion) { let m = DMatrix::::new_random(500, 500); - bh.iter(|| Eigen::new(m.clone(), 1.0e-7, 0)) + bh.bench_function("eigen_500x500", move |bh| bh.iter(|| Eigen::new(m.clone(), 1.0e-7, 0))); } -#[bench] -fn eigenvalues_100x100(bh: &mut Bencher) { +fn eigenvalues_100x100(bh: &mut criterion::Criterion) { let m = DMatrix::::new_random(100, 100); - bh.iter(|| m.clone().eigenvalues(1.0e-7, 0)) + bh.bench_function("eigenvalues_100x100", move |bh| bh.iter(|| m.clone().eigenvalues(1.0e-7, 0))); } -#[bench] -fn eigenvalues_500x500(bh: &mut Bencher) { +fn eigenvalues_500x500(bh: &mut criterion::Criterion) { let m = DMatrix::::new_random(500, 500); - bh.iter(|| m.clone().eigenvalues(1.0e-7, 0)) + bh.bench_function("eigenvalues_500x500", move |bh| bh.iter(|| m.clone().eigenvalues(1.0e-7, 0))); } + +criterion_group!(eigen, + eigen_100x100, +// eigen_500x500, + eigenvalues_100x100, +// eigenvalues_500x500 +); diff --git a/benches/linalg/full_piv_lu.rs b/benches/linalg/full_piv_lu.rs index ad82b069..6c7b1fa6 100644 --- a/benches/linalg/full_piv_lu.rs +++ b/benches/linalg/full_piv_lu.rs @@ -1,102 +1,105 @@ use na::{DMatrix, DVector, FullPivLU}; -use test::{self, Bencher}; // Without unpack. -#[bench] -fn full_piv_lu_decompose_10x10(bh: &mut Bencher) { +fn full_piv_lu_decompose_10x10(bh: &mut criterion::Criterion) { let m = DMatrix::::new_random(10, 10); - bh.iter(|| test::black_box(FullPivLU::new(m.clone()))) + bh.bench_function("full_piv_lu_decompose_10x10", move |bh| bh.iter(|| test::black_box(FullPivLU::new(m.clone())))); } -#[bench] -fn full_piv_lu_decompose_100x100(bh: &mut Bencher) { +fn full_piv_lu_decompose_100x100(bh: &mut criterion::Criterion) { let m = DMatrix::::new_random(100, 100); - bh.iter(|| test::black_box(FullPivLU::new(m.clone()))) + bh.bench_function("full_piv_lu_decompose_100x100", move |bh| bh.iter(|| test::black_box(FullPivLU::new(m.clone())))); } -#[bench] -fn full_piv_lu_decompose_500x500(bh: &mut Bencher) { +fn full_piv_lu_decompose_500x500(bh: &mut criterion::Criterion) { let m = DMatrix::::new_random(500, 500); - bh.iter(|| test::black_box(FullPivLU::new(m.clone()))) + bh.bench_function("full_piv_lu_decompose_500x500", move |bh| bh.iter(|| test::black_box(FullPivLU::new(m.clone())))); } -#[bench] -fn full_piv_lu_solve_10x10(bh: &mut Bencher) { +fn full_piv_lu_solve_10x10(bh: &mut criterion::Criterion) { let m = DMatrix::::new_random(10, 10); let lu = FullPivLU::new(m.clone()); - bh.iter(|| { + bh.bench_function("full_piv_lu_solve_10x10", move |bh| bh.iter(|| { let mut b = DVector::::from_element(10, 1.0); lu.solve(&mut b); - }) + })); } -#[bench] -fn full_piv_lu_solve_100x100(bh: &mut Bencher) { +fn full_piv_lu_solve_100x100(bh: &mut criterion::Criterion) { let m = DMatrix::::new_random(100, 100); let lu = FullPivLU::new(m.clone()); - bh.iter(|| { + bh.bench_function("full_piv_lu_solve_100x100", move |bh| bh.iter(|| { let mut b = DVector::::from_element(100, 1.0); lu.solve(&mut b); - }) + })); } -#[bench] -fn full_piv_lu_solve_500x500(bh: &mut Bencher) { +fn full_piv_lu_solve_500x500(bh: &mut criterion::Criterion) { let m = DMatrix::::new_random(500, 500); let lu = FullPivLU::new(m.clone()); - bh.iter(|| { + bh.bench_function("full_piv_lu_solve_500x500", move |bh| bh.iter(|| { let mut b = DVector::::from_element(500, 1.0); lu.solve(&mut b); - }) + })); } -#[bench] -fn full_piv_lu_inverse_10x10(bh: &mut Bencher) { +fn full_piv_lu_inverse_10x10(bh: &mut criterion::Criterion) { let m = DMatrix::::new_random(10, 10); let lu = FullPivLU::new(m.clone()); - bh.iter(|| test::black_box(lu.try_inverse())) + bh.bench_function("full_piv_lu_inverse_10x10", move |bh| bh.iter(|| test::black_box(lu.try_inverse()))); } -#[bench] -fn full_piv_lu_inverse_100x100(bh: &mut Bencher) { +fn full_piv_lu_inverse_100x100(bh: &mut criterion::Criterion) { let m = DMatrix::::new_random(100, 100); let lu = FullPivLU::new(m.clone()); - bh.iter(|| test::black_box(lu.try_inverse())) + bh.bench_function("full_piv_lu_inverse_100x100", move |bh| bh.iter(|| test::black_box(lu.try_inverse()))); } -#[bench] -fn full_piv_lu_inverse_500x500(bh: &mut Bencher) { +fn full_piv_lu_inverse_500x500(bh: &mut criterion::Criterion) { let m = DMatrix::::new_random(500, 500); let lu = FullPivLU::new(m.clone()); - bh.iter(|| test::black_box(lu.try_inverse())) + bh.bench_function("full_piv_lu_inverse_500x500", move |bh| bh.iter(|| test::black_box(lu.try_inverse()))); } -#[bench] -fn full_piv_lu_determinant_10x10(bh: &mut Bencher) { +fn full_piv_lu_determinant_10x10(bh: &mut criterion::Criterion) { let m = DMatrix::::new_random(10, 10); let lu = FullPivLU::new(m.clone()); - bh.iter(|| test::black_box(lu.determinant())) + bh.bench_function("full_piv_lu_determinant_10x10", move |bh| bh.iter(|| test::black_box(lu.determinant()))); } -#[bench] -fn full_piv_lu_determinant_100x100(bh: &mut Bencher) { + +fn full_piv_lu_determinant_100x100(bh: &mut criterion::Criterion) { let m = DMatrix::::new_random(100, 100); let lu = FullPivLU::new(m.clone()); - bh.iter(|| test::black_box(lu.determinant())) + bh.bench_function("full_piv_lu_determinant_100x100", move |bh| bh.iter(|| test::black_box(lu.determinant()))); } -#[bench] -fn full_piv_lu_determinant_500x500(bh: &mut Bencher) { +fn full_piv_lu_determinant_500x500(bh: &mut criterion::Criterion) { let m = DMatrix::::new_random(500, 500); let lu = FullPivLU::new(m.clone()); - bh.iter(|| test::black_box(lu.determinant())) + bh.bench_function("full_piv_lu_determinant_500x500", move |bh| bh.iter(|| test::black_box(lu.determinant()))); } + +criterion_group!(full_piv_lu, + full_piv_lu_decompose_10x10, + full_piv_lu_decompose_100x100, +// full_piv_lu_decompose_500x500, + full_piv_lu_solve_10x10, + full_piv_lu_solve_100x100, +// full_piv_lu_solve_500x500, + full_piv_lu_inverse_10x10, + full_piv_lu_inverse_100x100, +// full_piv_lu_inverse_500x500, + full_piv_lu_determinant_10x10, + full_piv_lu_determinant_100x100, +// full_piv_lu_determinant_500x500 +); \ No newline at end of file diff --git a/benches/linalg/hessenberg.rs b/benches/linalg/hessenberg.rs index 427aa1fe..3340c3ef 100644 --- a/benches/linalg/hessenberg.rs +++ b/benches/linalg/hessenberg.rs @@ -1,58 +1,60 @@ use na::{DMatrix, Hessenberg, Matrix4}; -use test::{self, Bencher}; #[path = "../common/macros.rs"] mod macros; // Without unpack. -#[bench] -fn hessenberg_decompose_4x4(bh: &mut Bencher) { +fn hessenberg_decompose_4x4(bh: &mut criterion::Criterion) { let m = Matrix4::::new_random(); - bh.iter(|| test::black_box(Hessenberg::new(m.clone()))) + bh.bench_function("hessenberg_decompose_4x4", move |bh| bh.iter(|| test::black_box(Hessenberg::new(m.clone())))); } -#[bench] -fn hessenberg_decompose_100x100(bh: &mut Bencher) { +fn hessenberg_decompose_100x100(bh: &mut criterion::Criterion) { let m = DMatrix::::new_random(100, 100); - bh.iter(|| test::black_box(Hessenberg::new(m.clone()))) + bh.bench_function("hessenberg_decompose_100x100", move |bh| bh.iter(|| test::black_box(Hessenberg::new(m.clone())))); } -#[bench] -fn hessenberg_decompose_200x200(bh: &mut Bencher) { +fn hessenberg_decompose_200x200(bh: &mut criterion::Criterion) { let m = DMatrix::::new_random(200, 200); - bh.iter(|| test::black_box(Hessenberg::new(m.clone()))) + bh.bench_function("hessenberg_decompose_200x200", move |bh| bh.iter(|| test::black_box(Hessenberg::new(m.clone())))); } -#[bench] -fn hessenberg_decompose_500x500(bh: &mut Bencher) { +fn hessenberg_decompose_500x500(bh: &mut criterion::Criterion) { let m = DMatrix::::new_random(500, 500); - bh.iter(|| test::black_box(Hessenberg::new(m.clone()))) + bh.bench_function("hessenberg_decompose_500x500", move |bh| bh.iter(|| test::black_box(Hessenberg::new(m.clone())))); } // With unpack. -#[bench] -fn hessenberg_decompose_unpack_100x100(bh: &mut Bencher) { +fn hessenberg_decompose_unpack_100x100(bh: &mut criterion::Criterion) { let m = DMatrix::::new_random(100, 100); - bh.iter(|| { + bh.bench_function("hessenberg_decompose_unpack_100x100", move |bh| bh.iter(|| { let hess = Hessenberg::new(m.clone()); let _ = hess.unpack(); - }) + })); } -#[bench] -fn hessenberg_decompose_unpack_200x200(bh: &mut Bencher) { +fn hessenberg_decompose_unpack_200x200(bh: &mut criterion::Criterion) { let m = DMatrix::::new_random(200, 200); - bh.iter(|| { + bh.bench_function("hessenberg_decompose_unpack_200x200", move |bh| bh.iter(|| { let hess = Hessenberg::new(m.clone()); let _ = hess.unpack(); - }) + })); } -#[bench] -fn hessenberg_decompose_unpack_500x500(bh: &mut Bencher) { +fn hessenberg_decompose_unpack_500x500(bh: &mut criterion::Criterion) { let m = DMatrix::::new_random(500, 500); - bh.iter(|| { + bh.bench_function("hessenberg_decompose_unpack_500x500", move |bh| bh.iter(|| { let hess = Hessenberg::new(m.clone()); let _ = hess.unpack(); - }) + })); } + +criterion_group!(hessenberg, + hessenberg_decompose_4x4, + hessenberg_decompose_100x100, + hessenberg_decompose_200x200, +// hessenberg_decompose_500x500, + hessenberg_decompose_unpack_100x100, + hessenberg_decompose_unpack_200x200, +// hessenberg_decompose_unpack_500x500 +); \ No newline at end of file diff --git a/benches/linalg/lu.rs b/benches/linalg/lu.rs index 2428cf9c..e37cfe75 100644 --- a/benches/linalg/lu.rs +++ b/benches/linalg/lu.rs @@ -1,102 +1,102 @@ use na::{DMatrix, DVector, LU}; -use test::{self, Bencher}; // Without unpack. -#[bench] -fn lu_decompose_10x10(bh: &mut Bencher) { +fn lu_decompose_10x10(bh: &mut criterion::Criterion) { let m = DMatrix::::new_random(10, 10); - bh.iter(|| test::black_box(LU::new(m.clone()))) + bh.bench_function("lu_decompose_10x10", move |bh| bh.iter(|| test::black_box(LU::new(m.clone())))); } -#[bench] -fn lu_decompose_100x100(bh: &mut Bencher) { +fn lu_decompose_100x100(bh: &mut criterion::Criterion) { let m = DMatrix::::new_random(100, 100); - bh.iter(|| test::black_box(LU::new(m.clone()))) + bh.bench_function("lu_decompose_100x100", move |bh| bh.iter(|| test::black_box(LU::new(m.clone())))); } -#[bench] -fn lu_decompose_500x500(bh: &mut Bencher) { +fn lu_decompose_500x500(bh: &mut criterion::Criterion) { let m = DMatrix::::new_random(500, 500); - bh.iter(|| test::black_box(LU::new(m.clone()))) + bh.bench_function("lu_decompose_500x500", move |bh| bh.iter(|| test::black_box(LU::new(m.clone())))); } -#[bench] -fn lu_solve_10x10(bh: &mut Bencher) { +fn lu_solve_10x10(bh: &mut criterion::Criterion) { let m = DMatrix::::new_random(10, 10); let lu = LU::new(m.clone()); - bh.iter(|| { + bh.bench_function("lu_solve_10x10", move |bh| bh.iter(|| { let mut b = DVector::::from_element(10, 1.0); lu.solve(&mut b); - }) + })); } -#[bench] -fn lu_solve_100x100(bh: &mut Bencher) { +fn lu_solve_100x100(bh: &mut criterion::Criterion) { let m = DMatrix::::new_random(100, 100); let lu = LU::new(m.clone()); - bh.iter(|| { + bh.bench_function("lu_solve_100x100", move |bh| bh.iter(|| { let mut b = DVector::::from_element(100, 1.0); lu.solve(&mut b); - }) + })); } -#[bench] -fn lu_solve_500x500(bh: &mut Bencher) { +fn lu_solve_500x500(bh: &mut criterion::Criterion) { let m = DMatrix::::new_random(500, 500); let lu = LU::new(m.clone()); - bh.iter(|| { + bh.bench_function("", move |bh| bh.iter(|| { let mut b = DVector::::from_element(500, 1.0); lu.solve(&mut b); - }) + })); } -#[bench] -fn lu_inverse_10x10(bh: &mut Bencher) { +fn lu_inverse_10x10(bh: &mut criterion::Criterion) { let m = DMatrix::::new_random(10, 10); let lu = LU::new(m.clone()); - bh.iter(|| test::black_box(lu.try_inverse())) + bh.bench_function("lu_inverse_10x10", move |bh| bh.iter(|| test::black_box(lu.try_inverse()))); } -#[bench] -fn lu_inverse_100x100(bh: &mut Bencher) { +fn lu_inverse_100x100(bh: &mut criterion::Criterion) { let m = DMatrix::::new_random(100, 100); let lu = LU::new(m.clone()); - bh.iter(|| test::black_box(lu.try_inverse())) + bh.bench_function("lu_inverse_100x100", move |bh| bh.iter(|| test::black_box(lu.try_inverse()))); } -#[bench] -fn lu_inverse_500x500(bh: &mut Bencher) { +fn lu_inverse_500x500(bh: &mut criterion::Criterion) { let m = DMatrix::::new_random(500, 500); let lu = LU::new(m.clone()); - bh.iter(|| test::black_box(lu.try_inverse())) + bh.bench_function("lu_inverse_500x500", move |bh| bh.iter(|| test::black_box(lu.try_inverse()))); } -#[bench] -fn lu_determinant_10x10(bh: &mut Bencher) { +fn lu_determinant_10x10(bh: &mut criterion::Criterion) { let m = DMatrix::::new_random(10, 10); let lu = LU::new(m.clone()); - bh.iter(|| test::black_box(lu.determinant())) + bh.bench_function("lu_determinant_10x10", move |bh| bh.iter(|| test::black_box(lu.determinant()))); } -#[bench] -fn lu_determinant_100x100(bh: &mut Bencher) { +fn lu_determinant_100x100(bh: &mut criterion::Criterion) { let m = DMatrix::::new_random(100, 100); let lu = LU::new(m.clone()); - bh.iter(|| test::black_box(lu.determinant())) + bh.bench_function("lu_determinant_100x100", move |bh| bh.iter(|| test::black_box(lu.determinant()))); } -#[bench] -fn lu_determinant_500x500(bh: &mut Bencher) { +fn lu_determinant_500x500(bh: &mut criterion::Criterion) { let m = DMatrix::::new_random(500, 500); let lu = LU::new(m.clone()); - bh.iter(|| test::black_box(lu.determinant())) + bh.bench_function("", move |bh| bh.iter(|| test::black_box(lu.determinant()))); } + +criterion_group!(lu, + lu_decompose_10x10, + lu_decompose_100x100, +// lu_decompose_500x500, + lu_solve_10x10, + lu_solve_100x100, + lu_inverse_10x10, + lu_inverse_100x100, +// lu_inverse_500x500, + lu_determinant_10x10, + lu_determinant_100x100 +); \ No newline at end of file diff --git a/benches/linalg/mod.rs b/benches/linalg/mod.rs index fb38835b..a6e7a8ef 100644 --- a/benches/linalg/mod.rs +++ b/benches/linalg/mod.rs @@ -1,4 +1,13 @@ pub use self::bidiagonal::bidiagonal; +pub use self::cholesky::cholesky; +pub use self::full_piv_lu::full_piv_lu; +pub use self::hessenberg::hessenberg; +pub use self::lu::lu; +pub use self::qr::qr; +pub use self::schur::schur; +pub use self::solve::solve; +pub use self::svd::svd; +pub use self::symmetric_eigen::symmetric_eigen; mod bidiagonal; mod cholesky; diff --git a/benches/linalg/qr.rs b/benches/linalg/qr.rs index 41a814ff..8283c5e9 100644 --- a/benches/linalg/qr.rs +++ b/benches/linalg/qr.rs @@ -1,130 +1,133 @@ use na::{DMatrix, DVector, Matrix4, QR}; -use test::{self, Bencher}; #[path = "../common/macros.rs"] mod macros; // Without unpack. -#[bench] -fn qr_decompose_100x100(bh: &mut Bencher) { +fn qr_decompose_100x100(bh: &mut criterion::Criterion) { let m = DMatrix::::new_random(100, 100); - bh.iter(|| test::black_box(QR::new(m.clone()))) + bh.bench_function("qr_decompose_100x100", move |bh| bh.iter(|| test::black_box(QR::new(m.clone())))); } -#[bench] -fn qr_decompose_100x500(bh: &mut Bencher) { +fn qr_decompose_100x500(bh: &mut criterion::Criterion) { let m = DMatrix::::new_random(100, 500); - bh.iter(|| test::black_box(QR::new(m.clone()))) + bh.bench_function("qr_decompose_100x500", move |bh| bh.iter(|| test::black_box(QR::new(m.clone())))); } -#[bench] -fn qr_decompose_4x4(bh: &mut Bencher) { +fn qr_decompose_4x4(bh: &mut criterion::Criterion) { let m = Matrix4::::new_random(); - bh.iter(|| test::black_box(QR::new(m.clone()))) + bh.bench_function("qr_decompose_4x4", move |bh| bh.iter(|| test::black_box(QR::new(m.clone())))); } -#[bench] -fn qr_decompose_500x100(bh: &mut Bencher) { +fn qr_decompose_500x100(bh: &mut criterion::Criterion) { let m = DMatrix::::new_random(500, 100); - bh.iter(|| test::black_box(QR::new(m.clone()))) + bh.bench_function("qr_decompose_500x100", move |bh| bh.iter(|| test::black_box(QR::new(m.clone())))); } -#[bench] -fn qr_decompose_500x500(bh: &mut Bencher) { +fn qr_decompose_500x500(bh: &mut criterion::Criterion) { let m = DMatrix::::new_random(500, 500); - bh.iter(|| test::black_box(QR::new(m.clone()))) + bh.bench_function("qr_decompose_500x500", move |bh| bh.iter(|| test::black_box(QR::new(m.clone())))); } // With unpack. -#[bench] -fn qr_decompose_unpack_100x100(bh: &mut Bencher) { +fn qr_decompose_unpack_100x100(bh: &mut criterion::Criterion) { let m = DMatrix::::new_random(100, 100); - bh.iter(|| { + bh.bench_function("qr_decompose_unpack_100x100", move |bh| bh.iter(|| { let qr = QR::new(m.clone()); let _ = qr.unpack(); - }) + })); } -#[bench] -fn qr_decompose_unpack_100x500(bh: &mut Bencher) { +fn qr_decompose_unpack_100x500(bh: &mut criterion::Criterion) { let m = DMatrix::::new_random(100, 500); - bh.iter(|| { + bh.bench_function("qr_decompose_unpack_100x500", move |bh| bh.iter(|| { let qr = QR::new(m.clone()); let _ = qr.unpack(); - }) + })); } -#[bench] -fn qr_decompose_unpack_500x100(bh: &mut Bencher) { +fn qr_decompose_unpack_500x100(bh: &mut criterion::Criterion) { let m = DMatrix::::new_random(500, 100); - bh.iter(|| { + bh.bench_function("qr_decompose_unpack_500x100", move |bh| bh.iter(|| { let qr = QR::new(m.clone()); let _ = qr.unpack(); - }) + })); } -#[bench] -fn qr_decompose_unpack_500x500(bh: &mut Bencher) { +fn qr_decompose_unpack_500x500(bh: &mut criterion::Criterion) { let m = DMatrix::::new_random(500, 500); - bh.iter(|| { + bh.bench_function("qr_decompose_unpack_500x500", move |bh| bh.iter(|| { let qr = QR::new(m.clone()); let _ = qr.unpack(); - }) + })); } -#[bench] -fn qr_solve_10x10(bh: &mut Bencher) { +fn qr_solve_10x10(bh: &mut criterion::Criterion) { let m = DMatrix::::new_random(10, 10); let qr = QR::new(m.clone()); - bh.iter(|| { + bh.bench_function("qr_solve_10x10", move |bh| bh.iter(|| { let mut b = DVector::::from_element(10, 1.0); qr.solve(&mut b); - }) + })); } -#[bench] -fn qr_solve_100x100(bh: &mut Bencher) { +fn qr_solve_100x100(bh: &mut criterion::Criterion) { let m = DMatrix::::new_random(100, 100); let qr = QR::new(m.clone()); - bh.iter(|| { + bh.bench_function("qr_solve_100x100", move |bh| bh.iter(|| { let mut b = DVector::::from_element(100, 1.0); qr.solve(&mut b); - }) + })); } -#[bench] -fn qr_solve_500x500(bh: &mut Bencher) { +fn qr_solve_500x500(bh: &mut criterion::Criterion) { let m = DMatrix::::new_random(500, 500); let qr = QR::new(m.clone()); - bh.iter(|| { + bh.bench_function("qr_solve_500x500", move |bh| bh.iter(|| { let mut b = DVector::::from_element(500, 1.0); qr.solve(&mut b); - }) + })); } -#[bench] -fn qr_inverse_10x10(bh: &mut Bencher) { +fn qr_inverse_10x10(bh: &mut criterion::Criterion) { let m = DMatrix::::new_random(10, 10); let qr = QR::new(m.clone()); - bh.iter(|| test::black_box(qr.try_inverse())) + bh.bench_function("qr_inverse_10x10", move |bh| bh.iter(|| test::black_box(qr.try_inverse()))); } -#[bench] -fn qr_inverse_100x100(bh: &mut Bencher) { +fn qr_inverse_100x100(bh: &mut criterion::Criterion) { let m = DMatrix::::new_random(100, 100); let qr = QR::new(m.clone()); - bh.iter(|| test::black_box(qr.try_inverse())) + bh.bench_function("qr_inverse_100x100", move |bh| bh.iter(|| test::black_box(qr.try_inverse()))); } -#[bench] -fn qr_inverse_500x500(bh: &mut Bencher) { +fn qr_inverse_500x500(bh: &mut criterion::Criterion) { let m = DMatrix::::new_random(500, 500); let qr = QR::new(m.clone()); - bh.iter(|| test::black_box(qr.try_inverse())) + bh.bench_function("qr_inverse_500x500", move |bh| bh.iter(|| test::black_box(qr.try_inverse()))); } + + +criterion_group!(qr, + qr_decompose_100x100, + qr_decompose_100x500, + qr_decompose_4x4, + qr_decompose_500x100, +// qr_decompose_500x500, + qr_decompose_unpack_100x100, + qr_decompose_unpack_100x500, + qr_decompose_unpack_500x100, +// qr_decompose_unpack_500x500, + qr_solve_10x10, + qr_solve_100x100, +// qr_solve_500x500, + qr_inverse_10x10, + qr_inverse_100x100, +// qr_inverse_500x500 +); \ No newline at end of file diff --git a/benches/linalg/schur.rs b/benches/linalg/schur.rs index 024e6114..ffabc539 100644 --- a/benches/linalg/schur.rs +++ b/benches/linalg/schur.rs @@ -1,50 +1,52 @@ use na::{Matrix4, Schur}; -use test::{self, Bencher}; -#[bench] -fn schur_decompose_4x4(bh: &mut Bencher) { +fn schur_decompose_4x4(bh: &mut criterion::Criterion) { let m = Matrix4::::new_random(); - bh.iter(|| test::black_box(Schur::new(m.clone()))) + bh.bench_function("schur_decompose_4x4", move |bh| bh.iter(|| test::black_box(Schur::new(m.clone())))); } -#[bench] -fn schur_decompose_10x10(bh: &mut Bencher) { +fn schur_decompose_10x10(bh: &mut criterion::Criterion) { let m = crate::reproductible_dmatrix(10, 10); - bh.iter(|| test::black_box(Schur::new(m.clone()))) + bh.bench_function("schur_decompose_10x10", move |bh| bh.iter(|| test::black_box(Schur::new(m.clone())))); } -#[bench] -fn schur_decompose_100x100(bh: &mut Bencher) { +fn schur_decompose_100x100(bh: &mut criterion::Criterion) { let m = crate::reproductible_dmatrix(100, 100); - bh.iter(|| test::black_box(Schur::new(m.clone()))) + bh.bench_function("schur_decompose_100x100", move |bh| bh.iter(|| test::black_box(Schur::new(m.clone())))); } -#[bench] -fn schur_decompose_200x200(bh: &mut Bencher) { +fn schur_decompose_200x200(bh: &mut criterion::Criterion) { let m = crate::reproductible_dmatrix(200, 200); - bh.iter(|| test::black_box(Schur::new(m.clone()))) + bh.bench_function("schur_decompose_200x200", move |bh| bh.iter(|| test::black_box(Schur::new(m.clone())))); } -#[bench] -fn eigenvalues_4x4(bh: &mut Bencher) { +fn eigenvalues_4x4(bh: &mut criterion::Criterion) { let m = Matrix4::::new_random(); - bh.iter(|| test::black_box(m.complex_eigenvalues())) + bh.bench_function("eigenvalues_4x4", move |bh| bh.iter(|| test::black_box(m.complex_eigenvalues()))); } -#[bench] -fn eigenvalues_10x10(bh: &mut Bencher) { +fn eigenvalues_10x10(bh: &mut criterion::Criterion) { let m = crate::reproductible_dmatrix(10, 10); - bh.iter(|| test::black_box(m.complex_eigenvalues())) + bh.bench_function("eigenvalues_10x10", move |bh| bh.iter(|| test::black_box(m.complex_eigenvalues()))); } -#[bench] -fn eigenvalues_100x100(bh: &mut Bencher) { +fn eigenvalues_100x100(bh: &mut criterion::Criterion) { let m = crate::reproductible_dmatrix(100, 100); - bh.iter(|| test::black_box(m.complex_eigenvalues())) + bh.bench_function("eigenvalues_100x100", move |bh| bh.iter(|| test::black_box(m.complex_eigenvalues()))); } -#[bench] -fn eigenvalues_200x200(bh: &mut Bencher) { +fn eigenvalues_200x200(bh: &mut criterion::Criterion) { let m = crate::reproductible_dmatrix(200, 200); - bh.iter(|| test::black_box(m.complex_eigenvalues())) + bh.bench_function("eigenvalues_200x200", move |bh| bh.iter(|| test::black_box(m.complex_eigenvalues()))); } + +criterion_group!(schur, + schur_decompose_4x4, + schur_decompose_10x10, + schur_decompose_100x100, + schur_decompose_200x200, + eigenvalues_4x4, + eigenvalues_10x10, + eigenvalues_100x100, + eigenvalues_200x200 +); \ No newline at end of file diff --git a/benches/linalg/solve.rs b/benches/linalg/solve.rs index 03ec71e5..51c6db59 100644 --- a/benches/linalg/solve.rs +++ b/benches/linalg/solve.rs @@ -1,82 +1,85 @@ use na::{DMatrix, DVector}; -use test::Bencher; -#[bench] -fn solve_l_triangular_100x100(bh: &mut Bencher) { +fn solve_l_triangular_100x100(bh: &mut criterion::Criterion) { let m = DMatrix::::new_random(100, 100); let v = DVector::::new_random(100); - bh.iter(|| { + bh.bench_function("solve_l_triangular_100x100", move |bh| bh.iter(|| { let _ = m.solve_lower_triangular(&v); - }) + })); } -#[bench] -fn solve_l_triangular_1000x1000(bh: &mut Bencher) { +fn solve_l_triangular_1000x1000(bh: &mut criterion::Criterion) { let m = DMatrix::::new_random(1000, 1000); let v = DVector::::new_random(1000); - bh.iter(|| { + bh.bench_function("solve_l_triangular_1000x1000", move |bh| bh.iter(|| { let _ = m.solve_lower_triangular(&v); - }) + })); } -#[bench] -fn tr_solve_l_triangular_100x100(bh: &mut Bencher) { +fn tr_solve_l_triangular_100x100(bh: &mut criterion::Criterion) { let m = DMatrix::::new_random(100, 100); let v = DVector::::new_random(100); - bh.iter(|| { + bh.bench_function("tr_solve_l_triangular_100x100", move |bh| bh.iter(|| { let _ = m.tr_solve_lower_triangular(&v); - }) + })); } -#[bench] -fn tr_solve_l_triangular_1000x1000(bh: &mut Bencher) { +fn tr_solve_l_triangular_1000x1000(bh: &mut criterion::Criterion) { let m = DMatrix::::new_random(1000, 1000); let v = DVector::::new_random(1000); - bh.iter(|| { + bh.bench_function("tr_solve_l_triangular_1000x1000", move |bh| bh.iter(|| { let _ = m.tr_solve_lower_triangular(&v); - }) + })); } -#[bench] -fn solve_u_triangular_100x100(bh: &mut Bencher) { +fn solve_u_triangular_100x100(bh: &mut criterion::Criterion) { let m = DMatrix::::new_random(100, 100); let v = DVector::::new_random(100); - bh.iter(|| { + bh.bench_function("solve_u_triangular_100x100", move |bh| bh.iter(|| { let _ = m.solve_upper_triangular(&v); - }) + })); } -#[bench] -fn solve_u_triangular_1000x1000(bh: &mut Bencher) { +fn solve_u_triangular_1000x1000(bh: &mut criterion::Criterion) { let m = DMatrix::::new_random(1000, 1000); let v = DVector::::new_random(1000); - bh.iter(|| { + bh.bench_function("solve_u_triangular_1000x1000", move |bh| bh.iter(|| { let _ = m.solve_upper_triangular(&v); - }) + })); } -#[bench] -fn tr_solve_u_triangular_100x100(bh: &mut Bencher) { +fn tr_solve_u_triangular_100x100(bh: &mut criterion::Criterion) { let m = DMatrix::::new_random(100, 100); let v = DVector::::new_random(100); - bh.iter(|| { + bh.bench_function("tr_solve_u_triangular_100x100", move |bh| bh.iter(|| { let _ = m.tr_solve_upper_triangular(&v); - }) + })); } -#[bench] -fn tr_solve_u_triangular_1000x1000(bh: &mut Bencher) { +fn tr_solve_u_triangular_1000x1000(bh: &mut criterion::Criterion) { let m = DMatrix::::new_random(1000, 1000); let v = DVector::::new_random(1000); - bh.iter(|| { + bh.bench_function("tr_solve_u_triangular_1000x1000", move |bh| bh.iter(|| { let _ = m.tr_solve_upper_triangular(&v); - }) + })); } + + +criterion_group!(solve, + solve_l_triangular_100x100, + solve_l_triangular_1000x1000, + tr_solve_l_triangular_100x100, + tr_solve_l_triangular_1000x1000, + solve_u_triangular_100x100, + solve_u_triangular_1000x1000, + tr_solve_u_triangular_100x100, + tr_solve_u_triangular_1000x1000 +); \ No newline at end of file diff --git a/benches/linalg/svd.rs b/benches/linalg/svd.rs index 956ba4a7..6804147c 100644 --- a/benches/linalg/svd.rs +++ b/benches/linalg/svd.rs @@ -1,98 +1,101 @@ use na::{Matrix4, SVD}; -use test::{self, Bencher}; -#[bench] -fn svd_decompose_4x4(bh: &mut Bencher) { +fn svd_decompose_4x4(bh: &mut criterion::Criterion) { let m = Matrix4::::new_random(); - bh.iter(|| test::black_box(SVD::new(m.clone(), true, true))) + bh.bench_function("svd_decompose_4x4", move |bh| bh.iter(|| test::black_box(SVD::new(m.clone(), true, true)))); } -#[bench] -fn svd_decompose_10x10(bh: &mut Bencher) { +fn svd_decompose_10x10(bh: &mut criterion::Criterion) { let m = crate::reproductible_dmatrix(10, 10); - bh.iter(|| test::black_box(SVD::new(m.clone(), true, true))) + bh.bench_function("svd_decompose_10x10", move |bh| bh.iter(|| test::black_box(SVD::new(m.clone(), true, true)))); } -#[bench] -fn svd_decompose_100x100(bh: &mut Bencher) { +fn svd_decompose_100x100(bh: &mut criterion::Criterion) { let m = crate::reproductible_dmatrix(100, 100); - bh.iter(|| test::black_box(SVD::new(m.clone(), true, true))) + bh.bench_function("svd_decompose_100x100", move |bh| bh.iter(|| test::black_box(SVD::new(m.clone(), true, true)))); } -#[bench] -fn svd_decompose_200x200(bh: &mut Bencher) { +fn svd_decompose_200x200(bh: &mut criterion::Criterion) { let m = crate::reproductible_dmatrix(200, 200); - bh.iter(|| test::black_box(SVD::new(m.clone(), true, true))) + bh.bench_function("svd_decompose_200x200", move |bh| bh.iter(|| test::black_box(SVD::new(m.clone(), true, true)))); } -#[bench] -fn rank_4x4(bh: &mut Bencher) { +fn rank_4x4(bh: &mut criterion::Criterion) { let m = Matrix4::::new_random(); - bh.iter(|| test::black_box(m.rank(1.0e-10))) + bh.bench_function("rank_4x4", move |bh| bh.iter(|| test::black_box(m.rank(1.0e-10)))); } -#[bench] -fn rank_10x10(bh: &mut Bencher) { +fn rank_10x10(bh: &mut criterion::Criterion) { let m = crate::reproductible_dmatrix(10, 10); - bh.iter(|| test::black_box(m.rank(1.0e-10))) + bh.bench_function("rank_10x10", move |bh| bh.iter(|| test::black_box(m.rank(1.0e-10)))); } -#[bench] -fn rank_100x100(bh: &mut Bencher) { +fn rank_100x100(bh: &mut criterion::Criterion) { let m = crate::reproductible_dmatrix(100, 100); - bh.iter(|| test::black_box(m.rank(1.0e-10))) + bh.bench_function("rank_100x100", move |bh| bh.iter(|| test::black_box(m.rank(1.0e-10)))); } -#[bench] -fn rank_200x200(bh: &mut Bencher) { +fn rank_200x200(bh: &mut criterion::Criterion) { let m = crate::reproductible_dmatrix(200, 200); - bh.iter(|| test::black_box(m.rank(1.0e-10))) + bh.bench_function("rank_200x200", move |bh| bh.iter(|| test::black_box(m.rank(1.0e-10)))); } -#[bench] -fn singular_values_4x4(bh: &mut Bencher) { +fn singular_values_4x4(bh: &mut criterion::Criterion) { let m = Matrix4::::new_random(); - bh.iter(|| test::black_box(m.singular_values())) + bh.bench_function("singular_values_4x4", move |bh| bh.iter(|| test::black_box(m.singular_values()))); } -#[bench] -fn singular_values_10x10(bh: &mut Bencher) { +fn singular_values_10x10(bh: &mut criterion::Criterion) { let m = crate::reproductible_dmatrix(10, 10); - bh.iter(|| test::black_box(m.singular_values())) + bh.bench_function("singular_values_10x10", move |bh| bh.iter(|| test::black_box(m.singular_values()))); } -#[bench] -fn singular_values_100x100(bh: &mut Bencher) { +fn singular_values_100x100(bh: &mut criterion::Criterion) { let m = crate::reproductible_dmatrix(100, 100); - bh.iter(|| test::black_box(m.singular_values())) + bh.bench_function("singular_values_100x100", move |bh| bh.iter(|| test::black_box(m.singular_values()))); } -#[bench] -fn singular_values_200x200(bh: &mut Bencher) { +fn singular_values_200x200(bh: &mut criterion::Criterion) { let m = crate::reproductible_dmatrix(200, 200); - bh.iter(|| test::black_box(m.singular_values())) + bh.bench_function("singular_values_200x200", move |bh| bh.iter(|| test::black_box(m.singular_values()))); } -#[bench] -fn pseudo_inverse_4x4(bh: &mut Bencher) { +fn pseudo_inverse_4x4(bh: &mut criterion::Criterion) { let m = Matrix4::::new_random(); - bh.iter(|| test::black_box(m.clone().pseudo_inverse(1.0e-10))) + bh.bench_function("pseudo_inverse_4x4", move |bh| bh.iter(|| test::black_box(m.clone().pseudo_inverse(1.0e-10)))); } -#[bench] -fn pseudo_inverse_10x10(bh: &mut Bencher) { +fn pseudo_inverse_10x10(bh: &mut criterion::Criterion) { let m = crate::reproductible_dmatrix(10, 10); - bh.iter(|| test::black_box(m.clone().pseudo_inverse(1.0e-10))) + bh.bench_function("pseudo_inverse_10x10", move |bh| bh.iter(|| test::black_box(m.clone().pseudo_inverse(1.0e-10)))); } -#[bench] -fn pseudo_inverse_100x100(bh: &mut Bencher) { +fn pseudo_inverse_100x100(bh: &mut criterion::Criterion) { let m = crate::reproductible_dmatrix(100, 100); - bh.iter(|| test::black_box(m.clone().pseudo_inverse(1.0e-10))) + bh.bench_function("pseudo_inverse_100x100", move |bh| bh.iter(|| test::black_box(m.clone().pseudo_inverse(1.0e-10)))); } -#[bench] -fn pseudo_inverse_200x200(bh: &mut Bencher) { +fn pseudo_inverse_200x200(bh: &mut criterion::Criterion) { let m = crate::reproductible_dmatrix(200, 200); - bh.iter(|| test::black_box(m.clone().pseudo_inverse(1.0e-10))) + bh.bench_function("pseudo_inverse_200x200", move |bh| bh.iter(|| test::black_box(m.clone().pseudo_inverse(1.0e-10)))); } + + +criterion_group!(svd, + svd_decompose_4x4, + svd_decompose_10x10, + svd_decompose_100x100, + svd_decompose_200x200, + rank_4x4, + rank_10x10, + rank_100x100, + rank_200x200, + singular_values_4x4, + singular_values_10x10, + singular_values_100x100, + singular_values_200x200, + pseudo_inverse_4x4, + pseudo_inverse_10x10, + pseudo_inverse_100x100, + pseudo_inverse_200x200 +); \ No newline at end of file diff --git a/benches/linalg/symmetric_eigen.rs b/benches/linalg/symmetric_eigen.rs index 7f19eb78..822ea30e 100644 --- a/benches/linalg/symmetric_eigen.rs +++ b/benches/linalg/symmetric_eigen.rs @@ -1,26 +1,28 @@ use na::{Matrix4, SymmetricEigen}; -use test::{self, Bencher}; -#[bench] -fn symmetric_eigen_decompose_4x4(bh: &mut Bencher) { +fn symmetric_eigen_decompose_4x4(bh: &mut criterion::Criterion) { let m = Matrix4::::new_random(); - bh.iter(|| test::black_box(SymmetricEigen::new(m.clone()))) + bh.bench_function("symmetric_eigen_decompose_4x4", move |bh| bh.iter(|| test::black_box(SymmetricEigen::new(m.clone())))); } -#[bench] -fn symmetric_eigen_decompose_10x10(bh: &mut Bencher) { +fn symmetric_eigen_decompose_10x10(bh: &mut criterion::Criterion) { let m = crate::reproductible_dmatrix(10, 10); - bh.iter(|| test::black_box(SymmetricEigen::new(m.clone()))) + bh.bench_function("symmetric_eigen_decompose_10x10", move |bh| bh.iter(|| test::black_box(SymmetricEigen::new(m.clone())))); } -#[bench] -fn symmetric_eigen_decompose_100x100(bh: &mut Bencher) { +fn symmetric_eigen_decompose_100x100(bh: &mut criterion::Criterion) { let m = crate::reproductible_dmatrix(100, 100); - bh.iter(|| test::black_box(SymmetricEigen::new(m.clone()))) + bh.bench_function("symmetric_eigen_decompose_100x100", move |bh| bh.iter(|| test::black_box(SymmetricEigen::new(m.clone())))); } -#[bench] -fn symmetric_eigen_decompose_200x200(bh: &mut Bencher) { +fn symmetric_eigen_decompose_200x200(bh: &mut criterion::Criterion) { let m = crate::reproductible_dmatrix(200, 200); - bh.iter(|| test::black_box(SymmetricEigen::new(m.clone()))) + bh.bench_function("symmetric_eigen_decompose_200x200", move |bh| bh.iter(|| test::black_box(SymmetricEigen::new(m.clone())))); } + +criterion_group!(symmetric_eigen, + symmetric_eigen_decompose_4x4, + symmetric_eigen_decompose_10x10, + symmetric_eigen_decompose_100x100, + symmetric_eigen_decompose_200x200 +);