2018-02-02 19:26:35 +08:00
|
|
|
use na::{DMatrix, DVector, Matrix4, QR};
|
2017-08-03 01:37:44 +08:00
|
|
|
|
2018-02-02 19:26:35 +08:00
|
|
|
#[path = "../common/macros.rs"]
|
2017-08-03 01:37:44 +08:00
|
|
|
mod macros;
|
|
|
|
|
|
|
|
// Without unpack.
|
2019-03-24 02:07:16 +08:00
|
|
|
fn qr_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("qr_decompose_100x100", move |bh| {
|
2021-04-12 16:52:17 +08:00
|
|
|
bh.iter(|| std::hint::black_box(QR::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 qr_decompose_100x500(bh: &mut criterion::Criterion) {
|
2017-08-03 01:37:44 +08:00
|
|
|
let m = DMatrix::<f64>::new_random(100, 500);
|
2020-04-06 00:49:48 +08:00
|
|
|
bh.bench_function("qr_decompose_100x500", move |bh| {
|
2021-04-12 16:52:17 +08:00
|
|
|
bh.iter(|| std::hint::black_box(QR::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 qr_decompose_4x4(bh: &mut criterion::Criterion) {
|
2017-08-03 01:37:44 +08:00
|
|
|
let m = Matrix4::<f64>::new_random();
|
2020-04-06 00:49:48 +08:00
|
|
|
bh.bench_function("qr_decompose_4x4", move |bh| {
|
2021-04-12 16:52:17 +08:00
|
|
|
bh.iter(|| std::hint::black_box(QR::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 qr_decompose_500x100(bh: &mut criterion::Criterion) {
|
2017-08-03 01:37:44 +08:00
|
|
|
let m = DMatrix::<f64>::new_random(500, 100);
|
2020-04-06 00:49:48 +08:00
|
|
|
bh.bench_function("qr_decompose_500x100", move |bh| {
|
2021-04-12 16:52:17 +08:00
|
|
|
bh.iter(|| std::hint::black_box(QR::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 qr_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("qr_decompose_500x500", move |bh| {
|
2021-04-12 16:52:17 +08:00
|
|
|
bh.iter(|| std::hint::black_box(QR::new(m.clone())))
|
2020-04-06 00:49:48 +08:00
|
|
|
});
|
2017-08-03 01:37:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// With unpack.
|
2019-03-24 02:07:16 +08:00
|
|
|
fn qr_decompose_unpack_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("qr_decompose_unpack_100x100", move |bh| {
|
|
|
|
bh.iter(|| {
|
|
|
|
let qr = QR::new(m.clone());
|
|
|
|
let _ = qr.unpack();
|
|
|
|
})
|
|
|
|
});
|
2017-08-03 01:37:44 +08:00
|
|
|
}
|
|
|
|
|
2019-03-24 02:07:16 +08:00
|
|
|
fn qr_decompose_unpack_100x500(bh: &mut criterion::Criterion) {
|
2017-08-03 01:37:44 +08:00
|
|
|
let m = DMatrix::<f64>::new_random(100, 500);
|
2020-04-06 00:49:48 +08:00
|
|
|
bh.bench_function("qr_decompose_unpack_100x500", move |bh| {
|
|
|
|
bh.iter(|| {
|
|
|
|
let qr = QR::new(m.clone());
|
|
|
|
let _ = qr.unpack();
|
|
|
|
})
|
|
|
|
});
|
2017-08-03 01:37:44 +08:00
|
|
|
}
|
|
|
|
|
2019-03-24 02:07:16 +08:00
|
|
|
fn qr_decompose_unpack_500x100(bh: &mut criterion::Criterion) {
|
2017-08-03 01:37:44 +08:00
|
|
|
let m = DMatrix::<f64>::new_random(500, 100);
|
2020-04-06 00:49:48 +08:00
|
|
|
bh.bench_function("qr_decompose_unpack_500x100", move |bh| {
|
|
|
|
bh.iter(|| {
|
|
|
|
let qr = QR::new(m.clone());
|
|
|
|
let _ = qr.unpack();
|
|
|
|
})
|
|
|
|
});
|
2017-08-03 01:37:44 +08:00
|
|
|
}
|
|
|
|
|
2019-03-24 02:07:16 +08:00
|
|
|
fn qr_decompose_unpack_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("qr_decompose_unpack_500x500", move |bh| {
|
|
|
|
bh.iter(|| {
|
|
|
|
let qr = QR::new(m.clone());
|
|
|
|
let _ = qr.unpack();
|
|
|
|
})
|
|
|
|
});
|
2017-08-03 01:37:44 +08:00
|
|
|
}
|
|
|
|
|
2019-03-24 02:07:16 +08:00
|
|
|
fn qr_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 qr = QR::new(m.clone());
|
|
|
|
|
2020-04-06 00:49:48 +08:00
|
|
|
bh.bench_function("qr_solve_10x10", move |bh| {
|
|
|
|
bh.iter(|| {
|
|
|
|
let mut b = DVector::<f64>::from_element(10, 1.0);
|
|
|
|
qr.solve(&mut b);
|
|
|
|
})
|
|
|
|
});
|
2017-08-03 01:37:44 +08:00
|
|
|
}
|
|
|
|
|
2019-03-24 02:07:16 +08:00
|
|
|
fn qr_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 qr = QR::new(m.clone());
|
|
|
|
|
2020-04-06 00:49:48 +08:00
|
|
|
bh.bench_function("qr_solve_100x100", move |bh| {
|
|
|
|
bh.iter(|| {
|
|
|
|
let mut b = DVector::<f64>::from_element(100, 1.0);
|
|
|
|
qr.solve(&mut b);
|
|
|
|
})
|
|
|
|
});
|
2017-08-03 01:37:44 +08:00
|
|
|
}
|
|
|
|
|
2019-03-24 02:07:16 +08:00
|
|
|
fn qr_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 qr = QR::new(m.clone());
|
|
|
|
|
2020-04-06 00:49:48 +08:00
|
|
|
bh.bench_function("qr_solve_500x500", move |bh| {
|
|
|
|
bh.iter(|| {
|
|
|
|
let mut b = DVector::<f64>::from_element(500, 1.0);
|
|
|
|
qr.solve(&mut b);
|
|
|
|
})
|
|
|
|
});
|
2017-08-03 01:37:44 +08:00
|
|
|
}
|
|
|
|
|
2019-03-24 02:07:16 +08:00
|
|
|
fn qr_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 qr = QR::new(m.clone());
|
|
|
|
|
2020-04-06 00:49:48 +08:00
|
|
|
bh.bench_function("qr_inverse_10x10", move |bh| {
|
2021-04-12 16:52:17 +08:00
|
|
|
bh.iter(|| std::hint::black_box(qr.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 qr_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 qr = QR::new(m.clone());
|
|
|
|
|
2020-04-06 00:49:48 +08:00
|
|
|
bh.bench_function("qr_inverse_100x100", move |bh| {
|
2021-04-12 16:52:17 +08:00
|
|
|
bh.iter(|| std::hint::black_box(qr.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 qr_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 qr = QR::new(m.clone());
|
|
|
|
|
2020-04-06 00:49:48 +08:00
|
|
|
bh.bench_function("qr_inverse_500x500", move |bh| {
|
2021-04-12 16:52:17 +08:00
|
|
|
bh.iter(|| std::hint::black_box(qr.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
|
|
|
|
2020-04-06 00:49:48 +08:00
|
|
|
criterion_group!(
|
|
|
|
qr,
|
2019-03-24 02:07:16 +08:00
|
|
|
qr_decompose_100x100,
|
|
|
|
qr_decompose_100x500,
|
|
|
|
qr_decompose_4x4,
|
|
|
|
qr_decompose_500x100,
|
2020-04-06 00:49:48 +08:00
|
|
|
// qr_decompose_500x500,
|
2019-03-24 02:07:16 +08:00
|
|
|
qr_decompose_unpack_100x100,
|
|
|
|
qr_decompose_unpack_100x500,
|
|
|
|
qr_decompose_unpack_500x100,
|
2020-04-06 00:49:48 +08:00
|
|
|
// qr_decompose_unpack_500x500,
|
2019-03-24 02:07:16 +08:00
|
|
|
qr_solve_10x10,
|
|
|
|
qr_solve_100x100,
|
2020-04-06 00:49:48 +08:00
|
|
|
// qr_solve_500x500,
|
2019-03-24 02:07:16 +08:00
|
|
|
qr_inverse_10x10,
|
|
|
|
qr_inverse_100x100,
|
2020-04-06 00:49:48 +08:00
|
|
|
// qr_inverse_500x500
|
|
|
|
);
|