Fix benchmarks

This commit is contained in:
Brendan Zabarauskas 2015-12-22 22:55:59 +11:00
parent ef34770a4b
commit 4c8fc61e23
5 changed files with 64 additions and 81 deletions

View file

@ -13,30 +13,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
macro_rules! bench_binop(
($name: ident, $t1: ty, $t2: ty, $binop: ident) => {
#[bench]
fn $name(bh: &mut Bencher) {
const LEN: usize = 1 << 13;
let mut rng = IsaacRng::new_unseeded();
let elems1: Vec<$t1> = (0..LEN).map(|_| rng.gen::<$t1>()).collect();
let elems2: Vec<$t2> = (0..LEN).map(|_| rng.gen::<$t2>()).collect();
let mut i = 0;
bh.iter(|| {
i = (i + 1) & (LEN - 1);
unsafe {
test::black_box(elems1.get_unchecked(i).$binop(elems2.get_unchecked(i)))
}
})
}
}
);
macro_rules! bench_binop_deref(
macro_rules! bench_binop {
($name: ident, $t1: ty, $t2: ty, $binop: ident) => {
#[bench]
fn $name(bh: &mut Bencher) {
@ -56,10 +33,10 @@ macro_rules! bench_binop_deref(
}
})
}
}
);
};
}
macro_rules! bench_unop(
macro_rules! bench_unop {
($name: ident, $t: ty, $unop: ident) => {
#[bench]
fn $name(bh: &mut Bencher) {
@ -78,10 +55,10 @@ macro_rules! bench_unop(
}
})
}
}
);
};
}
macro_rules! bench_construction(
macro_rules! bench_construction {
($name: ident, $t: ty, $constructor: path [ $($args: ident: $types: ty),+ ]) => {
#[bench]
fn $name(bh: &mut Bencher) {
@ -101,5 +78,5 @@ macro_rules! bench_construction(
}
})
}
}
);
};
}

View file

@ -39,7 +39,7 @@ fn bench_from_axis_angle<T: Rotation3<f32>>(bh: &mut Bencher) {
i = (i + 1) & (LEN - 1);
unsafe {
let res: T = Rotation3::from_axis_angle(axis.get_unchecked(i), *angle.get_unchecked(i));
let res: T = Rotation3::from_axis_angle(*axis.get_unchecked(i), *angle.get_unchecked(i));
test::black_box(res)
}
})

View file

@ -20,35 +20,37 @@ extern crate test;
extern crate cgmath;
use rand::{IsaacRng, Rng};
use std::ops::*;
use test::Bencher;
use cgmath::*;
#[path="common/macros.rs"]
#[macro_use] mod macros;
bench_binop!(_bench_matrix2_mul_m, Matrix2<f32>, Matrix2<f32>, mul_m);
bench_binop!(_bench_matrix3_mul_m, Matrix3<f32>, Matrix3<f32>, mul_m);
bench_binop!(_bench_matrix4_mul_m, Matrix4<f32>, Matrix4<f32>, mul_m);
bench_binop!(_bench_matrix2_mul_m, Matrix2<f32>, Matrix2<f32>, mul);
bench_binop!(_bench_matrix3_mul_m, Matrix3<f32>, Matrix3<f32>, mul);
bench_binop!(_bench_matrix4_mul_m, Matrix4<f32>, Matrix4<f32>, mul);
bench_binop!(_bench_matrix2_add_m, Matrix2<f32>, Matrix2<f32>, add_m);
bench_binop!(_bench_matrix3_add_m, Matrix3<f32>, Matrix3<f32>, add_m);
bench_binop!(_bench_matrix4_add_m, Matrix4<f32>, Matrix4<f32>, add_m);
bench_binop!(_bench_matrix2_add_m, Matrix2<f32>, Matrix2<f32>, add);
bench_binop!(_bench_matrix3_add_m, Matrix3<f32>, Matrix3<f32>, add);
bench_binop!(_bench_matrix4_add_m, Matrix4<f32>, Matrix4<f32>, add);
bench_binop!(_bench_matrix2_sub_m, Matrix2<f32>, Matrix2<f32>, sub_m);
bench_binop!(_bench_matrix3_sub_m, Matrix3<f32>, Matrix3<f32>, sub_m);
bench_binop!(_bench_matrix4_sub_m, Matrix4<f32>, Matrix4<f32>, sub_m);
bench_binop!(_bench_matrix2_sub_m, Matrix2<f32>, Matrix2<f32>, sub);
bench_binop!(_bench_matrix3_sub_m, Matrix3<f32>, Matrix3<f32>, sub);
bench_binop!(_bench_matrix4_sub_m, Matrix4<f32>, Matrix4<f32>, sub);
bench_binop!(_bench_matrix2_mul_v, Matrix2<f32>, Vector2<f32>, mul_v);
bench_binop!(_bench_matrix3_mul_v, Matrix3<f32>, Vector3<f32>, mul_v);
bench_binop!(_bench_matrix4_mul_v, Matrix4<f32>, Vector4<f32>, mul_v);
bench_binop!(_bench_matrix2_mul_v, Matrix2<f32>, Vector2<f32>, mul);
bench_binop!(_bench_matrix3_mul_v, Matrix3<f32>, Vector3<f32>, mul);
bench_binop!(_bench_matrix4_mul_v, Matrix4<f32>, Vector4<f32>, mul);
bench_binop_deref!(_bench_matrix2_mul_s, Matrix2<f32>, f32, mul_s);
bench_binop_deref!(_bench_matrix3_mul_s, Matrix3<f32>, f32, mul_s);
bench_binop_deref!(_bench_matrix4_mul_s, Matrix4<f32>, f32, mul_s);
bench_binop!(_bench_matrix2_mul_s, Matrix2<f32>, f32, mul);
bench_binop!(_bench_matrix3_mul_s, Matrix3<f32>, f32, mul);
bench_binop!(_bench_matrix4_mul_s, Matrix4<f32>, f32, mul);
bench_binop_deref!(_bench_matrix2_div_s, Matrix2<f32>, f32, div_s);
bench_binop_deref!(_bench_matrix3_div_s, Matrix3<f32>, f32, div_s);
bench_binop_deref!(_bench_matrix4_div_s, Matrix4<f32>, f32, div_s);
bench_binop!(_bench_matrix2_div_s, Matrix2<f32>, f32, div);
bench_binop!(_bench_matrix3_div_s, Matrix3<f32>, f32, div);
bench_binop!(_bench_matrix4_div_s, Matrix4<f32>, f32, div);
bench_unop!(_bench_matrix2_invert, Matrix2<f32>, invert);
bench_unop!(_bench_matrix3_invert, Matrix3<f32>, invert);

View file

@ -20,18 +20,20 @@ extern crate test;
extern crate cgmath;
use rand::{IsaacRng, Rng};
use std::ops::*;
use test::Bencher;
use cgmath::*;
#[path="common/macros.rs"]
#[macro_use] mod macros;
bench_binop!(_bench_quat_add_q, Quaternion<f32>, Quaternion<f32>, add_q);
bench_binop!(_bench_quat_sub_q, Quaternion<f32>, Quaternion<f32>, sub_q);
bench_binop!(_bench_quat_mul_q, Quaternion<f32>, Quaternion<f32>, mul_q);
bench_binop!(_bench_quat_mul_v, Quaternion<f32>, Vector3<f32>, mul_v);
bench_binop_deref!(_bench_quat_mul_s, Quaternion<f32>, f32, mul_s);
bench_binop_deref!(_bench_quat_div_s, Quaternion<f32>, f32, div_s);
bench_binop!(_bench_quat_add_q, Quaternion<f32>, Quaternion<f32>, add);
bench_binop!(_bench_quat_sub_q, Quaternion<f32>, Quaternion<f32>, sub);
bench_binop!(_bench_quat_mul_q, Quaternion<f32>, Quaternion<f32>, mul);
bench_binop!(_bench_quat_mul_v, Quaternion<f32>, Vector3<f32>, mul);
bench_binop!(_bench_quat_mul_s, Quaternion<f32>, f32, mul);
bench_binop!(_bench_quat_div_s, Quaternion<f32>, f32, div);
bench_unop!(_bench_quat_invert, Quaternion<f32>, invert);
bench_unop!(_bench_quat_conjugate, Quaternion<f32>, conjugate);
bench_unop!(_bench_quat_normalize, Quaternion<f32>, normalize);

View file

@ -20,43 +20,45 @@ extern crate test;
extern crate cgmath;
use rand::{IsaacRng, Rng};
use std::ops::*;
use test::Bencher;
use cgmath::*;
#[path="common/macros.rs"]
#[macro_use] mod macros;
bench_binop!(_bench_vector2_add_v, Vector2<f32>, Vector2<f32>, add_v);
bench_binop!(_bench_vector3_add_v, Vector3<f32>, Vector3<f32>, add_v);
bench_binop!(_bench_vector4_add_v, Vector4<f32>, Vector4<f32>, add_v);
bench_binop!(_bench_vector2_add_v, Vector2<f32>, Vector2<f32>, add);
bench_binop!(_bench_vector3_add_v, Vector3<f32>, Vector3<f32>, add);
bench_binop!(_bench_vector4_add_v, Vector4<f32>, Vector4<f32>, add);
bench_binop!(_bench_vector2_sub_v, Vector2<f32>, Vector2<f32>, sub_v);
bench_binop!(_bench_vector3_sub_v, Vector3<f32>, Vector3<f32>, sub_v);
bench_binop!(_bench_vector4_sub_v, Vector4<f32>, Vector4<f32>, sub_v);
bench_binop!(_bench_vector2_sub_v, Vector2<f32>, Vector2<f32>, sub);
bench_binop!(_bench_vector3_sub_v, Vector3<f32>, Vector3<f32>, sub);
bench_binop!(_bench_vector4_sub_v, Vector4<f32>, Vector4<f32>, sub);
bench_binop!(_bench_vector2_mul_v, Vector2<f32>, Vector2<f32>, mul_v);
bench_binop!(_bench_vector3_mul_v, Vector3<f32>, Vector3<f32>, mul_v);
bench_binop!(_bench_vector4_mul_v, Vector4<f32>, Vector4<f32>, mul_v);
bench_binop!(_bench_vector2_mul_v, Vector2<f32>, Vector2<f32>, mul);
bench_binop!(_bench_vector3_mul_v, Vector3<f32>, Vector3<f32>, mul);
bench_binop!(_bench_vector4_mul_v, Vector4<f32>, Vector4<f32>, mul);
bench_binop!(_bench_vector2_div_v, Vector2<f32>, Vector2<f32>, div_v);
bench_binop!(_bench_vector3_div_v, Vector3<f32>, Vector3<f32>, div_v);
bench_binop!(_bench_vector4_div_v, Vector4<f32>, Vector4<f32>, div_v);
bench_binop!(_bench_vector2_div_v, Vector2<f32>, Vector2<f32>, div);
bench_binop!(_bench_vector3_div_v, Vector3<f32>, Vector3<f32>, div);
bench_binop!(_bench_vector4_div_v, Vector4<f32>, Vector4<f32>, div);
bench_binop_deref!(_bench_vector2_add_s, Vector2<f32>, f32, add_s);
bench_binop_deref!(_bench_vector3_add_s, Vector3<f32>, f32, add_s);
bench_binop_deref!(_bench_vector4_add_s, Vector4<f32>, f32, add_s);
bench_binop!(_bench_vector2_add_s, Vector2<f32>, f32, add);
bench_binop!(_bench_vector3_add_s, Vector3<f32>, f32, add);
bench_binop!(_bench_vector4_add_s, Vector4<f32>, f32, add);
bench_binop_deref!(_bench_vector2_sub_s, Vector2<f32>, f32, sub_s);
bench_binop_deref!(_bench_vector3_sub_s, Vector3<f32>, f32, sub_s);
bench_binop_deref!(_bench_vector4_sub_s, Vector4<f32>, f32, sub_s);
bench_binop!(_bench_vector2_sub_s, Vector2<f32>, f32, sub);
bench_binop!(_bench_vector3_sub_s, Vector3<f32>, f32, sub);
bench_binop!(_bench_vector4_sub_s, Vector4<f32>, f32, sub);
bench_binop_deref!(_bench_vector2_mul_s, Vector2<f32>, f32, mul_s);
bench_binop_deref!(_bench_vector3_mul_s, Vector3<f32>, f32, mul_s);
bench_binop_deref!(_bench_vector4_mul_s, Vector4<f32>, f32, mul_s);
bench_binop!(_bench_vector2_mul_s, Vector2<f32>, f32, mul);
bench_binop!(_bench_vector3_mul_s, Vector3<f32>, f32, mul);
bench_binop!(_bench_vector4_mul_s, Vector4<f32>, f32, mul);
bench_binop_deref!(_bench_vector2_div_s, Vector2<f32>, f32, div_s);
bench_binop_deref!(_bench_vector3_div_s, Vector3<f32>, f32, div_s);
bench_binop_deref!(_bench_vector4_div_s, Vector4<f32>, f32, div_s);
bench_binop!(_bench_vector2_div_s, Vector2<f32>, f32, div);
bench_binop!(_bench_vector3_div_s, Vector3<f32>, f32, div);
bench_binop!(_bench_vector4_div_s, Vector4<f32>, f32, div);
bench_binop!(_bench_vector2_dot, Vector2<f32>, Vector2<f32>, dot);