2017-08-03 01:37:44 +08:00
|
|
|
use na::{DMatrix, DVector, LU};
|
|
|
|
|
|
|
|
// Without unpack.
|
2019-03-24 02:07:16 +08:00
|
|
|
fn lu_decompose_10x10(bh: &mut criterion::Criterion) {
|
2017-08-03 01:37:44 +08:00
|
|
|
let m = DMatrix::<f64>::new_random(10, 10);
|
2020-04-06 00:49:48 +08:00
|
|
|
bh.bench_function("lu_decompose_10x10", move |bh| {
|
2021-04-12 16:52:17 +08:00
|
|
|
bh.iter(|| std::hint::black_box(LU::new(m.clone())))
|
2020-04-06 00:49:48 +08:00
|
|
|
});
|
2017-08-03 01:37:44 +08:00
|
|
|
}
|
|
|
|
|
2019-03-24 02:07:16 +08:00
|
|
|
fn lu_decompose_100x100(bh: &mut criterion::Criterion) {
|
2017-08-03 01:37:44 +08:00
|
|
|
let m = DMatrix::<f64>::new_random(100, 100);
|
2020-04-06 00:49:48 +08:00
|
|
|
bh.bench_function("lu_decompose_100x100", move |bh| {
|
2021-04-12 16:52:17 +08:00
|
|
|
bh.iter(|| std::hint::black_box(LU::new(m.clone())))
|
2020-04-06 00:49:48 +08:00
|
|
|
});
|
2017-08-03 01:37:44 +08:00
|
|
|
}
|
|
|
|
|
2019-03-24 02:07:16 +08:00
|
|
|
fn lu_decompose_500x500(bh: &mut criterion::Criterion) {
|
2017-08-03 01:37:44 +08:00
|
|
|
let m = DMatrix::<f64>::new_random(500, 500);
|
2020-04-06 00:49:48 +08:00
|
|
|
bh.bench_function("lu_decompose_500x500", move |bh| {
|
2021-04-12 16:52:17 +08:00
|
|
|
bh.iter(|| std::hint::black_box(LU::new(m.clone())))
|
2020-04-06 00:49:48 +08:00
|
|
|
});
|
2017-08-03 01:37:44 +08:00
|
|
|
}
|
|
|
|
|
2019-03-24 02:07:16 +08:00
|
|
|
fn lu_solve_10x10(bh: &mut criterion::Criterion) {
|
2018-02-02 19:26:35 +08:00
|
|
|
let m = DMatrix::<f64>::new_random(10, 10);
|
2017-08-03 01:37:44 +08:00
|
|
|
let lu = LU::new(m.clone());
|
|
|
|
|
2020-04-06 00:49:48 +08:00
|
|
|
bh.bench_function("lu_solve_10x10", move |bh| {
|
|
|
|
bh.iter(|| {
|
|
|
|
let mut b = DVector::<f64>::from_element(10, 1.0);
|
|
|
|
lu.solve(&mut b);
|
|
|
|
})
|
|
|
|
});
|
2017-08-03 01:37:44 +08:00
|
|
|
}
|
|
|
|
|
2019-03-24 02:07:16 +08:00
|
|
|
fn lu_solve_100x100(bh: &mut criterion::Criterion) {
|
2018-02-02 19:26:35 +08:00
|
|
|
let m = DMatrix::<f64>::new_random(100, 100);
|
2017-08-03 01:37:44 +08:00
|
|
|
let lu = LU::new(m.clone());
|
|
|
|
|
2020-04-06 00:49:48 +08:00
|
|
|
bh.bench_function("lu_solve_100x100", move |bh| {
|
|
|
|
bh.iter(|| {
|
|
|
|
let mut b = DVector::<f64>::from_element(100, 1.0);
|
|
|
|
lu.solve(&mut b);
|
|
|
|
})
|
|
|
|
});
|
2017-08-03 01:37:44 +08:00
|
|
|
}
|
|
|
|
|
2019-03-24 02:07:16 +08:00
|
|
|
fn lu_solve_500x500(bh: &mut criterion::Criterion) {
|
2018-02-02 19:26:35 +08:00
|
|
|
let m = DMatrix::<f64>::new_random(500, 500);
|
2017-08-03 01:37:44 +08:00
|
|
|
let lu = LU::new(m.clone());
|
|
|
|
|
2020-04-06 00:49:48 +08:00
|
|
|
bh.bench_function("", move |bh| {
|
|
|
|
bh.iter(|| {
|
|
|
|
let mut b = DVector::<f64>::from_element(500, 1.0);
|
|
|
|
lu.solve(&mut b);
|
|
|
|
})
|
|
|
|
});
|
2017-08-03 01:37:44 +08:00
|
|
|
}
|
|
|
|
|
2019-03-24 02:07:16 +08:00
|
|
|
fn lu_inverse_10x10(bh: &mut criterion::Criterion) {
|
2018-02-02 19:26:35 +08:00
|
|
|
let m = DMatrix::<f64>::new_random(10, 10);
|
2017-08-03 01:37:44 +08:00
|
|
|
let lu = LU::new(m.clone());
|
|
|
|
|
2020-04-06 00:49:48 +08:00
|
|
|
bh.bench_function("lu_inverse_10x10", move |bh| {
|
2021-04-12 16:52:17 +08:00
|
|
|
bh.iter(|| std::hint::black_box(lu.try_inverse()))
|
2020-04-06 00:49:48 +08:00
|
|
|
});
|
2017-08-03 01:37:44 +08:00
|
|
|
}
|
|
|
|
|
2019-03-24 02:07:16 +08:00
|
|
|
fn lu_inverse_100x100(bh: &mut criterion::Criterion) {
|
2018-02-02 19:26:35 +08:00
|
|
|
let m = DMatrix::<f64>::new_random(100, 100);
|
2017-08-03 01:37:44 +08:00
|
|
|
let lu = LU::new(m.clone());
|
|
|
|
|
2020-04-06 00:49:48 +08:00
|
|
|
bh.bench_function("lu_inverse_100x100", move |bh| {
|
2021-04-12 16:52:17 +08:00
|
|
|
bh.iter(|| std::hint::black_box(lu.try_inverse()))
|
2020-04-06 00:49:48 +08:00
|
|
|
});
|
2017-08-03 01:37:44 +08:00
|
|
|
}
|
|
|
|
|
2019-03-24 02:07:16 +08:00
|
|
|
fn lu_inverse_500x500(bh: &mut criterion::Criterion) {
|
2018-02-02 19:26:35 +08:00
|
|
|
let m = DMatrix::<f64>::new_random(500, 500);
|
2017-08-03 01:37:44 +08:00
|
|
|
let lu = LU::new(m.clone());
|
|
|
|
|
2020-04-06 00:49:48 +08:00
|
|
|
bh.bench_function("lu_inverse_500x500", move |bh| {
|
2021-04-12 16:52:17 +08:00
|
|
|
bh.iter(|| std::hint::black_box(lu.try_inverse()))
|
2020-04-06 00:49:48 +08:00
|
|
|
});
|
2017-08-03 01:37:44 +08:00
|
|
|
}
|
|
|
|
|
2019-03-24 02:07:16 +08:00
|
|
|
fn lu_determinant_10x10(bh: &mut criterion::Criterion) {
|
2018-02-02 19:26:35 +08:00
|
|
|
let m = DMatrix::<f64>::new_random(10, 10);
|
2017-08-03 01:37:44 +08:00
|
|
|
let lu = LU::new(m.clone());
|
|
|
|
|
2020-04-06 00:49:48 +08:00
|
|
|
bh.bench_function("lu_determinant_10x10", move |bh| {
|
2021-04-12 16:52:17 +08:00
|
|
|
bh.iter(|| std::hint::black_box(lu.determinant()))
|
2020-04-06 00:49:48 +08:00
|
|
|
});
|
2017-08-03 01:37:44 +08:00
|
|
|
}
|
|
|
|
|
2019-03-24 02:07:16 +08:00
|
|
|
fn lu_determinant_100x100(bh: &mut criterion::Criterion) {
|
2018-02-02 19:26:35 +08:00
|
|
|
let m = DMatrix::<f64>::new_random(100, 100);
|
2017-08-03 01:37:44 +08:00
|
|
|
let lu = LU::new(m.clone());
|
|
|
|
|
2020-04-06 00:49:48 +08:00
|
|
|
bh.bench_function("lu_determinant_100x100", move |bh| {
|
2021-04-12 16:52:17 +08:00
|
|
|
bh.iter(|| std::hint::black_box(lu.determinant()))
|
2020-04-06 00:49:48 +08:00
|
|
|
});
|
2017-08-03 01:37:44 +08:00
|
|
|
}
|
|
|
|
|
2019-03-24 02:07:16 +08:00
|
|
|
fn lu_determinant_500x500(bh: &mut criterion::Criterion) {
|
2018-02-02 19:26:35 +08:00
|
|
|
let m = DMatrix::<f64>::new_random(500, 500);
|
2017-08-03 01:37:44 +08:00
|
|
|
let lu = LU::new(m.clone());
|
|
|
|
|
2021-04-12 16:52:17 +08:00
|
|
|
bh.bench_function("", move |bh| {
|
|
|
|
bh.iter(|| std::hint::black_box(lu.determinant()))
|
|
|
|
});
|
2017-08-03 01:37:44 +08:00
|
|
|
}
|
2019-03-24 02:07:16 +08:00
|
|
|
|
2020-04-06 00:49:48 +08:00
|
|
|
criterion_group!(
|
|
|
|
lu,
|
2019-03-24 02:07:16 +08:00
|
|
|
lu_decompose_10x10,
|
|
|
|
lu_decompose_100x100,
|
2020-04-06 00:49:48 +08:00
|
|
|
// lu_decompose_500x500,
|
2019-03-24 02:07:16 +08:00
|
|
|
lu_solve_10x10,
|
|
|
|
lu_solve_100x100,
|
|
|
|
lu_inverse_10x10,
|
|
|
|
lu_inverse_100x100,
|
2020-04-06 00:49:48 +08:00
|
|
|
// lu_inverse_500x500,
|
2019-03-24 02:07:16 +08:00
|
|
|
lu_determinant_10x10,
|
|
|
|
lu_determinant_100x100
|
2020-04-06 00:49:48 +08:00
|
|
|
);
|