| 1 |
use na::{DMatrix, DVector, Matrix4, QR}; |
| 2 |
|
| 3 |
#[path = "../common/macros.rs"] |
| 4 |
mod macros; |
| 5 |
|
| 6 |
// Without unpack. |
| 7 |
fn qr_decompose_100x100(bh: &mut criterion::Criterion) { |
| 8 |
let m = DMatrix::<f64>::new_random(100, 100); |
| 9 |
bh.bench_function("qr_decompose_100x100", move |bh| { |
| 10 |
bh.iter(|| std::hint::black_box(QR::new(m.clone()))) |
| 11 |
}); |
| 12 |
} |
| 13 |
|
| 14 |
fn qr_decompose_100x500(bh: &mut criterion::Criterion) { |
| 15 |
let m = DMatrix::<f64>::new_random(100, 500); |
| 16 |
bh.bench_function("qr_decompose_100x500", move |bh| { |
| 17 |
bh.iter(|| std::hint::black_box(QR::new(m.clone()))) |
| 18 |
}); |
| 19 |
} |
| 20 |
|
| 21 |
fn qr_decompose_4x4(bh: &mut criterion::Criterion) { |
| 22 |
let m = Matrix4::<f64>::new_random(); |
| 23 |
bh.bench_function("qr_decompose_4x4", move |bh| { |
| 24 |
bh.iter(|| std::hint::black_box(QR::new(m.clone()))) |
| 25 |
}); |
| 26 |
} |
| 27 |
|
| 28 |
fn qr_decompose_500x100(bh: &mut criterion::Criterion) { |
| 29 |
let m = DMatrix::<f64>::new_random(500, 100); |
| 30 |
bh.bench_function("qr_decompose_500x100", move |bh| { |
| 31 |
bh.iter(|| std::hint::black_box(QR::new(m.clone()))) |
| 32 |
}); |
| 33 |
} |
| 34 |
|
| 35 |
// With unpack. |
| 36 |
fn qr_decompose_unpack_100x100(bh: &mut criterion::Criterion) { |
| 37 |
let m = DMatrix::<f64>::new_random(100, 100); |
| 38 |
bh.bench_function("qr_decompose_unpack_100x100", move |bh| { |
| 39 |
bh.iter(|| { |
| 40 |
let qr = QR::new(m.clone()); |
| 41 |
let _ = qr.unpack(); |
| 42 |
}) |
| 43 |
}); |
| 44 |
} |
| 45 |
|
| 46 |
fn qr_decompose_unpack_100x500(bh: &mut criterion::Criterion) { |
| 47 |
let m = DMatrix::<f64>::new_random(100, 500); |
| 48 |
bh.bench_function("qr_decompose_unpack_100x500", move |bh| { |
| 49 |
bh.iter(|| { |
| 50 |
let qr = QR::new(m.clone()); |
| 51 |
let _ = qr.unpack(); |
| 52 |
}) |
| 53 |
}); |
| 54 |
} |
| 55 |
|
| 56 |
fn qr_decompose_unpack_500x100(bh: &mut criterion::Criterion) { |
| 57 |
let m = DMatrix::<f64>::new_random(500, 100); |
| 58 |
bh.bench_function("qr_decompose_unpack_500x100", move |bh| { |
| 59 |
bh.iter(|| { |
| 60 |
let qr = QR::new(m.clone()); |
| 61 |
let _ = qr.unpack(); |
| 62 |
}) |
| 63 |
}); |
| 64 |
} |
| 65 |
|
| 66 |
fn qr_solve_10x10(bh: &mut criterion::Criterion) { |
| 67 |
let m = DMatrix::<f64>::new_random(10, 10); |
| 68 |
let qr = QR::new(m.clone()); |
| 69 |
|
| 70 |
bh.bench_function("qr_solve_10x10", move |bh| { |
| 71 |
bh.iter(|| { |
| 72 |
let mut b = DVector::<f64>::from_element(10, 1.0); |
| 73 |
qr.solve_mut(&mut b); |
| 74 |
b |
| 75 |
}) |
| 76 |
}); |
| 77 |
} |
| 78 |
|
| 79 |
fn qr_solve_100x100(bh: &mut criterion::Criterion) { |
| 80 |
let m = DMatrix::<f64>::new_random(100, 100); |
| 81 |
let qr = QR::new(m.clone()); |
| 82 |
|
| 83 |
bh.bench_function("qr_solve_100x100", move |bh| { |
| 84 |
bh.iter(|| { |
| 85 |
let mut b = DVector::<f64>::from_element(100, 1.0); |
| 86 |
qr.solve_mut(&mut b); |
| 87 |
b |
| 88 |
}) |
| 89 |
}); |
| 90 |
} |
| 91 |
|
| 92 |
fn qr_inverse_10x10(bh: &mut criterion::Criterion) { |
| 93 |
let m = DMatrix::<f64>::new_random(10, 10); |
| 94 |
let qr = QR::new(m.clone()); |
| 95 |
|
| 96 |
bh.bench_function("qr_inverse_10x10", move |bh| { |
| 97 |
bh.iter(|| std::hint::black_box(qr.try_inverse())) |
| 98 |
}); |
| 99 |
} |
| 100 |
|
| 101 |
fn qr_inverse_100x100(bh: &mut criterion::Criterion) { |
| 102 |
let m = DMatrix::<f64>::new_random(100, 100); |
| 103 |
let qr = QR::new(m.clone()); |
| 104 |
|
| 105 |
bh.bench_function("qr_inverse_100x100", move |bh| { |
| 106 |
bh.iter(|| std::hint::black_box(qr.try_inverse())) |
| 107 |
}); |
| 108 |
} |
| 109 |
|
| 110 |
criterion_group!( |
| 111 |
qr, |
| 112 |
qr_decompose_100x100, |
| 113 |
qr_decompose_100x500, |
| 114 |
qr_decompose_4x4, |
| 115 |
qr_decompose_500x100, |
| 116 |
qr_decompose_unpack_100x100, |
| 117 |
qr_decompose_unpack_100x500, |
| 118 |
qr_decompose_unpack_500x100, |
| 119 |
qr_solve_10x10, |
| 120 |
qr_solve_100x100, |
| 121 |
qr_inverse_10x10, |
| 122 |
qr_inverse_100x100, |
| 123 |
); |