2015-02-17 21:10:08 +08:00
|
|
|
#![feature(test)]
|
|
|
|
|
2014-11-07 23:15:56 +08:00
|
|
|
extern crate test;
|
2015-03-29 19:32:14 +08:00
|
|
|
extern crate nalgebra as na;
|
2014-11-07 23:15:56 +08:00
|
|
|
|
|
|
|
use test::Bencher;
|
2014-11-08 02:23:46 +08:00
|
|
|
use na::{DVec, DMat};
|
2014-11-07 23:15:56 +08:00
|
|
|
|
|
|
|
macro_rules! bench_mul_dmat(
|
|
|
|
($bh: expr, $nrows: expr, $ncols: expr) => {
|
|
|
|
{
|
|
|
|
$bh.iter(|| {
|
2014-12-18 06:28:32 +08:00
|
|
|
let a: DMat<f64> = DMat::new_random($nrows, $ncols);
|
|
|
|
let mut b: DMat<f64> = DMat::new_random($nrows, $ncols);
|
|
|
|
|
2016-01-10 21:49:37 +08:00
|
|
|
for _ in 0usize .. 1000 {
|
2014-12-18 06:28:32 +08:00
|
|
|
// XXX: the clone here is highly undesirable!
|
|
|
|
b = a.clone() * b;
|
2014-11-07 23:15:56 +08:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
2014-12-27 18:15:13 +08:00
|
|
|
);
|
2014-11-07 23:15:56 +08:00
|
|
|
|
|
|
|
#[bench]
|
|
|
|
fn bench_mul_dmat2(bh: &mut Bencher) {
|
2014-12-27 18:15:13 +08:00
|
|
|
bench_mul_dmat!(bh, 2, 2);
|
2014-11-07 23:15:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#[bench]
|
|
|
|
fn bench_mul_dmat3(bh: &mut Bencher) {
|
2014-12-27 18:15:13 +08:00
|
|
|
bench_mul_dmat!(bh, 3, 3);
|
2014-11-07 23:15:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#[bench]
|
|
|
|
fn bench_mul_dmat4(bh: &mut Bencher) {
|
2014-12-27 18:15:13 +08:00
|
|
|
bench_mul_dmat!(bh, 4, 4);
|
2014-11-07 23:15:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#[bench]
|
|
|
|
fn bench_mul_dmat5(bh: &mut Bencher) {
|
2014-12-27 18:15:13 +08:00
|
|
|
bench_mul_dmat!(bh, 5, 5);
|
2014-11-07 23:15:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#[bench]
|
|
|
|
fn bench_mul_dmat6(bh: &mut Bencher) {
|
2014-12-27 18:15:13 +08:00
|
|
|
bench_mul_dmat!(bh, 6, 6);
|
2014-11-07 23:15:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
macro_rules! bench_mul_dmat_dvec(
|
|
|
|
($bh: expr, $nrows: expr, $ncols: expr) => {
|
|
|
|
{
|
|
|
|
|
|
|
|
$bh.iter(|| {
|
2014-12-18 06:28:32 +08:00
|
|
|
let m : DMat<f64> = DMat::new_random($nrows, $ncols);
|
|
|
|
let mut v : DVec<f64> = DVec::new_random($ncols);
|
|
|
|
|
2016-01-10 21:49:37 +08:00
|
|
|
for _ in 0usize .. 1000 {
|
2014-12-18 06:28:32 +08:00
|
|
|
// XXX: the clone here is highly undesirable!
|
|
|
|
v = m.clone() * v
|
2014-11-07 23:15:56 +08:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
2014-12-27 18:15:13 +08:00
|
|
|
);
|
2014-11-07 23:15:56 +08:00
|
|
|
|
|
|
|
#[bench]
|
|
|
|
fn bench_mul_dmat_dvec2(bh: &mut Bencher) {
|
2014-12-27 18:15:13 +08:00
|
|
|
bench_mul_dmat_dvec!(bh, 2, 2);
|
2014-11-07 23:15:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#[bench]
|
|
|
|
fn bench_mul_dmat_dvec3(bh: &mut Bencher) {
|
2014-12-27 18:15:13 +08:00
|
|
|
bench_mul_dmat_dvec!(bh, 3, 3);
|
2014-11-07 23:15:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#[bench]
|
|
|
|
fn bench_mul_dmat_dvec4(bh: &mut Bencher) {
|
2014-12-27 18:15:13 +08:00
|
|
|
bench_mul_dmat_dvec!(bh, 4, 4);
|
2014-11-07 23:15:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#[bench]
|
|
|
|
fn bench_mul_dmat_dvec5(bh: &mut Bencher) {
|
2014-12-27 18:15:13 +08:00
|
|
|
bench_mul_dmat_dvec!(bh, 5, 5);
|
2014-11-07 23:15:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#[bench]
|
|
|
|
fn bench_mul_dmat_dvec6(bh: &mut Bencher) {
|
2014-12-27 18:15:13 +08:00
|
|
|
bench_mul_dmat_dvec!(bh, 6, 6);
|
2014-11-07 23:15:56 +08:00
|
|
|
}
|