2014-09-29 01:20:22 +08:00
|
|
|
#![feature(macro_rules)]
|
|
|
|
|
|
|
|
extern crate test;
|
|
|
|
extern crate "nalgebra" as na;
|
|
|
|
|
2014-06-01 21:21:45 +08:00
|
|
|
use std::rand::random;
|
2014-04-13 16:24:17 +08:00
|
|
|
use test::Bencher;
|
2013-10-08 07:22:56 +08:00
|
|
|
use na::{Vec2, Vec3, Vec4, Vec5, Vec6, DVec, Mat2, Mat3, Mat4, Mat5, Mat6, DMat};
|
2013-09-13 19:21:42 +08:00
|
|
|
|
|
|
|
macro_rules! bench_mul_mat(
|
|
|
|
($bh: expr, $t: ty) => {
|
|
|
|
{
|
|
|
|
let a: $t = random();
|
|
|
|
let mut b: $t = random();
|
|
|
|
|
2013-11-27 18:16:16 +08:00
|
|
|
$bh.iter(|| {
|
2014-07-05 16:24:43 +08:00
|
|
|
for _ in range(0u, 1000) {
|
2013-09-13 19:21:42 +08:00
|
|
|
b = a * b;
|
2014-01-30 18:28:15 +08:00
|
|
|
}
|
2013-11-27 18:16:16 +08:00
|
|
|
})
|
2013-09-13 19:21:42 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
#[bench]
|
2014-04-13 16:24:17 +08:00
|
|
|
fn bench_mul_mat2(bh: &mut Bencher) {
|
2013-09-13 19:21:42 +08:00
|
|
|
bench_mul_mat!(bh, Mat2<f64>)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[bench]
|
2014-04-13 16:24:17 +08:00
|
|
|
fn bench_mul_mat3(bh: &mut Bencher) {
|
2013-09-13 19:21:42 +08:00
|
|
|
bench_mul_mat!(bh, Mat3<f64>)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[bench]
|
2014-04-13 16:24:17 +08:00
|
|
|
fn bench_mul_mat4(bh: &mut Bencher) {
|
2013-09-13 19:21:42 +08:00
|
|
|
bench_mul_mat!(bh, Mat4<f64>)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[bench]
|
2014-04-13 16:24:17 +08:00
|
|
|
fn bench_mul_mat5(bh: &mut Bencher) {
|
2013-09-13 19:21:42 +08:00
|
|
|
bench_mul_mat!(bh, Mat5<f64>)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[bench]
|
2014-04-13 16:24:17 +08:00
|
|
|
fn bench_mul_mat6(bh: &mut Bencher) {
|
2013-09-13 19:21:42 +08:00
|
|
|
bench_mul_mat!(bh, Mat6<f64>)
|
|
|
|
}
|
|
|
|
|
|
|
|
macro_rules! bench_mul_dmat(
|
|
|
|
($bh: expr, $nrows: expr, $ncols: expr) => {
|
|
|
|
{
|
|
|
|
let a: DMat<f64> = DMat::new_random($nrows, $ncols);
|
|
|
|
let mut b: DMat<f64> = DMat::new_random($nrows, $ncols);
|
|
|
|
|
2013-11-27 18:16:16 +08:00
|
|
|
$bh.iter(|| {
|
2014-07-05 16:24:43 +08:00
|
|
|
for _ in range(0u, 1000) {
|
2013-09-13 19:21:42 +08:00
|
|
|
b = a * b;
|
2014-01-30 18:28:15 +08:00
|
|
|
}
|
2013-11-27 18:16:16 +08:00
|
|
|
})
|
2013-09-13 19:21:42 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
#[bench]
|
2014-04-13 16:24:17 +08:00
|
|
|
fn bench_mul_dmat2(bh: &mut Bencher) {
|
2013-09-13 19:21:42 +08:00
|
|
|
bench_mul_dmat!(bh, 2, 2)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[bench]
|
2014-04-13 16:24:17 +08:00
|
|
|
fn bench_mul_dmat3(bh: &mut Bencher) {
|
2013-09-13 19:21:42 +08:00
|
|
|
bench_mul_dmat!(bh, 3, 3)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[bench]
|
2014-04-13 16:24:17 +08:00
|
|
|
fn bench_mul_dmat4(bh: &mut Bencher) {
|
2013-09-13 19:21:42 +08:00
|
|
|
bench_mul_dmat!(bh, 4, 4)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[bench]
|
2014-04-13 16:24:17 +08:00
|
|
|
fn bench_mul_dmat5(bh: &mut Bencher) {
|
2013-09-13 19:21:42 +08:00
|
|
|
bench_mul_dmat!(bh, 5, 5)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[bench]
|
2014-04-13 16:24:17 +08:00
|
|
|
fn bench_mul_dmat6(bh: &mut Bencher) {
|
2013-09-13 19:21:42 +08:00
|
|
|
bench_mul_dmat!(bh, 6, 6)
|
|
|
|
}
|
|
|
|
|
|
|
|
macro_rules! bench_mul_mat_vec(
|
|
|
|
($bh: expr, $tm: ty, $tv: ty) => {
|
|
|
|
{
|
|
|
|
let m : $tm = random();
|
|
|
|
let mut v : $tv = random();
|
|
|
|
|
2013-11-27 18:16:16 +08:00
|
|
|
$bh.iter(|| {
|
2014-07-05 16:24:43 +08:00
|
|
|
for _ in range(0u, 1000) {
|
2013-09-15 16:48:18 +08:00
|
|
|
v = m * v
|
2014-01-30 18:28:15 +08:00
|
|
|
}
|
2013-11-27 18:16:16 +08:00
|
|
|
})
|
2013-09-13 19:21:42 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
#[bench]
|
2014-04-13 16:24:17 +08:00
|
|
|
fn bench_mul_mat_vec2(bh: &mut Bencher) {
|
2013-09-13 19:21:42 +08:00
|
|
|
bench_mul_mat_vec!(bh, Mat2<f64>, Vec2<f64>)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[bench]
|
2014-04-13 16:24:17 +08:00
|
|
|
fn bench_mul_mat_vec3(bh: &mut Bencher) {
|
2013-09-13 19:21:42 +08:00
|
|
|
bench_mul_mat_vec!(bh, Mat3<f64>, Vec3<f64>)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[bench]
|
2014-04-13 16:24:17 +08:00
|
|
|
fn bench_mul_mat_vec4(bh: &mut Bencher) {
|
2013-09-13 19:21:42 +08:00
|
|
|
bench_mul_mat_vec!(bh, Mat4<f64>, Vec4<f64>)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[bench]
|
2014-04-13 16:24:17 +08:00
|
|
|
fn bench_mul_mat_vec5(bh: &mut Bencher) {
|
2013-09-13 19:21:42 +08:00
|
|
|
bench_mul_mat_vec!(bh, Mat5<f64>, Vec5<f64>)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[bench]
|
2014-04-13 16:24:17 +08:00
|
|
|
fn bench_mul_mat_vec6(bh: &mut Bencher) {
|
2013-09-13 19:21:42 +08:00
|
|
|
bench_mul_mat_vec!(bh, Mat6<f64>, Vec6<f64>)
|
|
|
|
}
|
|
|
|
|
|
|
|
macro_rules! bench_mul_dmat_dvec(
|
|
|
|
($bh: expr, $nrows: expr, $ncols: expr) => {
|
|
|
|
{
|
|
|
|
let m : DMat<f64> = DMat::new_random($nrows, $ncols);
|
|
|
|
let mut v : DVec<f64> = DVec::new_random($ncols);
|
|
|
|
|
2013-11-27 18:16:16 +08:00
|
|
|
$bh.iter(|| {
|
2014-07-05 16:24:43 +08:00
|
|
|
for _ in range(0u, 1000) {
|
2013-09-15 16:48:18 +08:00
|
|
|
v = m * v
|
2014-01-30 18:28:15 +08:00
|
|
|
}
|
2013-11-27 18:16:16 +08:00
|
|
|
})
|
2013-09-13 19:21:42 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
#[bench]
|
2014-04-13 16:24:17 +08:00
|
|
|
fn bench_mul_dmat_dvec2(bh: &mut Bencher) {
|
2013-09-13 19:21:42 +08:00
|
|
|
bench_mul_dmat_dvec!(bh, 2, 2)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[bench]
|
2014-04-13 16:24:17 +08:00
|
|
|
fn bench_mul_dmat_dvec3(bh: &mut Bencher) {
|
2013-09-13 19:21:42 +08:00
|
|
|
bench_mul_dmat_dvec!(bh, 3, 3)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[bench]
|
2014-04-13 16:24:17 +08:00
|
|
|
fn bench_mul_dmat_dvec4(bh: &mut Bencher) {
|
2013-09-13 19:21:42 +08:00
|
|
|
bench_mul_dmat_dvec!(bh, 4, 4)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[bench]
|
2014-04-13 16:24:17 +08:00
|
|
|
fn bench_mul_dmat_dvec5(bh: &mut Bencher) {
|
2013-09-13 19:21:42 +08:00
|
|
|
bench_mul_dmat_dvec!(bh, 5, 5)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[bench]
|
2014-04-13 16:24:17 +08:00
|
|
|
fn bench_mul_dmat_dvec6(bh: &mut Bencher) {
|
2013-09-13 19:21:42 +08:00
|
|
|
bench_mul_dmat_dvec!(bh, 6, 6)
|
|
|
|
}
|