2014-03-14 06:20:04 +08:00
|
|
|
use 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};
|
|
|
|
use na;
|
2013-09-13 19:21:42 +08:00
|
|
|
|
|
|
|
macro_rules! bench_dot_vec(
|
|
|
|
($bh: expr, $t: ty) => {
|
|
|
|
{
|
|
|
|
let a: $t = random();
|
|
|
|
let b: $t = random();
|
|
|
|
let mut d = 0.0;
|
|
|
|
|
2013-11-27 18:16:16 +08:00
|
|
|
$bh.iter(|| {
|
2014-01-30 18:28:15 +08:00
|
|
|
for _ in range(0, 1000) {
|
2013-10-08 07:22:56 +08:00
|
|
|
d = d + na::dot(&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_dot_vec2(bh: &mut Bencher) {
|
2013-09-13 19:21:42 +08:00
|
|
|
bench_dot_vec!(bh, Vec2<f64>)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[bench]
|
2014-04-13 16:24:17 +08:00
|
|
|
fn bench_dot_vec3(bh: &mut Bencher) {
|
2013-09-13 19:21:42 +08:00
|
|
|
bench_dot_vec!(bh, Vec3<f64>)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[bench]
|
2014-04-13 16:24:17 +08:00
|
|
|
fn bench_dot_vec4(bh: &mut Bencher) {
|
2013-09-13 19:21:42 +08:00
|
|
|
bench_dot_vec!(bh, Vec4<f64>)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[bench]
|
2014-04-13 16:24:17 +08:00
|
|
|
fn bench_dot_vec5(bh: &mut Bencher) {
|
2013-09-13 19:21:42 +08:00
|
|
|
bench_dot_vec!(bh, Vec5<f64>)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[bench]
|
2014-04-13 16:24:17 +08:00
|
|
|
fn bench_dot_vec6(bh: &mut Bencher) {
|
2013-09-13 19:21:42 +08:00
|
|
|
bench_dot_vec!(bh, Vec6<f64>)
|
|
|
|
}
|