use rand::{IsaacRng, Rng}; use test::{self, Bencher}; use typenum::U10000; use na::{Vector2, Vector3, Vector4, VectorN, DVector}; use std::ops::{Add, Sub, Mul, Div}; #[path="../common/macros.rs"] mod macros; bench_binop!(vec2_add_v_f32, Vector2, Vector2, add); bench_binop!(vec3_add_v_f32, Vector3, Vector3, add); bench_binop!(vec4_add_v_f32, Vector4, Vector4, add); bench_binop!(vec2_add_v_f64, Vector2, Vector2, add); bench_binop!(vec3_add_v_f64, Vector3, Vector3, add); bench_binop!(vec4_add_v_f64, Vector4, Vector4, add); bench_binop!(vec2_sub_v, Vector2, Vector2, sub); bench_binop!(vec3_sub_v, Vector3, Vector3, sub); bench_binop!(vec4_sub_v, Vector4, Vector4, sub); bench_binop!(vec2_mul_s, Vector2, f32, mul); bench_binop!(vec3_mul_s, Vector3, f32, mul); bench_binop!(vec4_mul_s, Vector4, f32, mul); bench_binop!(vec2_div_s, Vector2, f32, div); bench_binop!(vec3_div_s, Vector3, f32, div); bench_binop!(vec4_div_s, Vector4, f32, div); bench_binop_ref!(vec2_dot_f32, Vector2, Vector2, dot); bench_binop_ref!(vec3_dot_f32, Vector3, Vector3, dot); bench_binop_ref!(vec4_dot_f32, Vector4, Vector4, dot); bench_binop_ref!(vec2_dot_f64, Vector2, Vector2, dot); bench_binop_ref!(vec3_dot_f64, Vector3, Vector3, dot); bench_binop_ref!(vec4_dot_f64, Vector4, Vector4, dot); bench_binop_ref!(vec3_cross, Vector3, Vector3, cross); bench_unop!(vec2_norm, Vector2, norm); bench_unop!(vec3_norm, Vector3, norm); bench_unop!(vec4_norm, Vector4, norm); bench_unop!(vec2_normalize, Vector2, normalize); bench_unop!(vec3_normalize, Vector3, normalize); bench_unop!(vec4_normalize, Vector4, normalize); bench_binop_ref!(vec10000_dot_f64, VectorN, VectorN, dot); bench_binop_ref!(vec10000_dot_f32, VectorN, VectorN, dot); #[bench] fn vec10000_axpy_f64(bh: &mut Bencher) { let mut rng = IsaacRng::new_unseeded(); let mut a = DVector::new_random(10000); let b = DVector::new_random(10000); let n = rng.gen::(); bh.iter(|| { a.axpy(n, &b, 1.0) }) } #[bench] fn vec10000_axpy_beta_f64(bh: &mut Bencher) { let mut rng = IsaacRng::new_unseeded(); let mut a = DVector::new_random(10000); let b = DVector::new_random(10000); let n = rng.gen::(); let beta = rng.gen::(); bh.iter(|| { a.axpy(n, &b, beta) }) } #[bench] fn vec10000_axpy_f64_slice(bh: &mut Bencher) { let mut rng = IsaacRng::new_unseeded(); let mut a = DVector::new_random(10000); let b = DVector::new_random(10000); let n = rng.gen::(); bh.iter(|| { let mut a = a.fixed_rows_mut::(0); let b = b.fixed_rows::(0); a.axpy(n, &b, 1.0) }) } #[bench] fn vec10000_axpy_f64_static(bh: &mut Bencher) { let mut rng = IsaacRng::new_unseeded(); let mut a = VectorN::::new_random(); let b = VectorN::::new_random(); let n = rng.gen::(); // NOTE: for some reasons, it is much faster if the arument are boxed (Box::new(VectorN...)). bh.iter(|| { a.axpy(n, &b, 1.0) }) } #[bench] fn vec10000_axpy_f32(bh: &mut Bencher) { let mut rng = IsaacRng::new_unseeded(); let mut a = DVector::new_random(10000); let b = DVector::new_random(10000); let n = rng.gen::(); bh.iter(|| { a.axpy(n, &b, 1.0) }) } #[bench] fn vec10000_axpy_beta_f32(bh: &mut Bencher) { let mut rng = IsaacRng::new_unseeded(); let mut a = DVector::new_random(10000); let b = DVector::new_random(10000); let n = rng.gen::(); let beta = rng.gen::(); bh.iter(|| { a.axpy(n, &b, beta) }) }