2018-10-22 13:00:10 +08:00
|
|
|
use na::{DVector, Vector2, Vector3, Vector4, VectorN};
|
2017-08-03 01:37:44 +08:00
|
|
|
use rand::{IsaacRng, Rng};
|
2018-10-22 13:00:10 +08:00
|
|
|
use std::ops::{Add, Div, Mul, Sub};
|
2017-08-03 01:37:44 +08:00
|
|
|
use typenum::U10000;
|
|
|
|
|
2018-02-02 19:26:35 +08:00
|
|
|
#[path = "../common/macros.rs"]
|
2017-08-03 01:37:44 +08:00
|
|
|
mod macros;
|
|
|
|
|
|
|
|
bench_binop!(vec2_add_v_f32, Vector2<f32>, Vector2<f32>, add);
|
|
|
|
bench_binop!(vec3_add_v_f32, Vector3<f32>, Vector3<f32>, add);
|
|
|
|
bench_binop!(vec4_add_v_f32, Vector4<f32>, Vector4<f32>, add);
|
|
|
|
|
|
|
|
bench_binop!(vec2_add_v_f64, Vector2<f64>, Vector2<f64>, add);
|
|
|
|
bench_binop!(vec3_add_v_f64, Vector3<f64>, Vector3<f64>, add);
|
|
|
|
bench_binop!(vec4_add_v_f64, Vector4<f64>, Vector4<f64>, add);
|
|
|
|
|
|
|
|
bench_binop!(vec2_sub_v, Vector2<f32>, Vector2<f32>, sub);
|
|
|
|
bench_binop!(vec3_sub_v, Vector3<f32>, Vector3<f32>, sub);
|
|
|
|
bench_binop!(vec4_sub_v, Vector4<f32>, Vector4<f32>, sub);
|
|
|
|
|
|
|
|
bench_binop!(vec2_mul_s, Vector2<f32>, f32, mul);
|
|
|
|
bench_binop!(vec3_mul_s, Vector3<f32>, f32, mul);
|
|
|
|
bench_binop!(vec4_mul_s, Vector4<f32>, f32, mul);
|
|
|
|
|
|
|
|
bench_binop!(vec2_div_s, Vector2<f32>, f32, div);
|
|
|
|
bench_binop!(vec3_div_s, Vector3<f32>, f32, div);
|
|
|
|
bench_binop!(vec4_div_s, Vector4<f32>, f32, div);
|
|
|
|
|
|
|
|
bench_binop_ref!(vec2_dot_f32, Vector2<f32>, Vector2<f32>, dot);
|
|
|
|
bench_binop_ref!(vec3_dot_f32, Vector3<f32>, Vector3<f32>, dot);
|
|
|
|
bench_binop_ref!(vec4_dot_f32, Vector4<f32>, Vector4<f32>, dot);
|
|
|
|
|
|
|
|
bench_binop_ref!(vec2_dot_f64, Vector2<f64>, Vector2<f64>, dot);
|
|
|
|
bench_binop_ref!(vec3_dot_f64, Vector3<f64>, Vector3<f64>, dot);
|
|
|
|
bench_binop_ref!(vec4_dot_f64, Vector4<f64>, Vector4<f64>, dot);
|
|
|
|
|
|
|
|
bench_binop_ref!(vec3_cross, Vector3<f32>, Vector3<f32>, cross);
|
|
|
|
|
|
|
|
bench_unop!(vec2_norm, Vector2<f32>, norm);
|
|
|
|
bench_unop!(vec3_norm, Vector3<f32>, norm);
|
|
|
|
bench_unop!(vec4_norm, Vector4<f32>, norm);
|
|
|
|
|
|
|
|
bench_unop!(vec2_normalize, Vector2<f32>, normalize);
|
|
|
|
bench_unop!(vec3_normalize, Vector3<f32>, normalize);
|
|
|
|
bench_unop!(vec4_normalize, Vector4<f32>, normalize);
|
|
|
|
|
|
|
|
bench_binop_ref!(vec10000_dot_f64, VectorN<f64, U10000>, VectorN<f64, U10000>, dot);
|
|
|
|
bench_binop_ref!(vec10000_dot_f32, VectorN<f32, U10000>, VectorN<f32, U10000>, dot);
|
|
|
|
|
2019-03-24 01:01:04 +08:00
|
|
|
fn vec10000_axpy_f64(bh: &mut criterion::Criterion) {
|
2018-12-29 19:12:56 +08:00
|
|
|
use rand::SeedableRng;
|
|
|
|
let mut rng = IsaacRng::seed_from_u64(0);
|
2017-08-03 01:37:44 +08:00
|
|
|
let mut a = DVector::new_random(10000);
|
|
|
|
let b = DVector::new_random(10000);
|
|
|
|
let n = rng.gen::<f64>();
|
|
|
|
|
2019-03-24 01:01:04 +08:00
|
|
|
bh.bench_function("", move |bh| bh.iter(|| a.axpy(n, &b, 1.0)));
|
2017-08-03 01:37:44 +08:00
|
|
|
}
|
|
|
|
|
2019-03-24 01:01:04 +08:00
|
|
|
fn vec10000_axpy_beta_f64(bh: &mut criterion::Criterion) {
|
2018-12-29 19:12:56 +08:00
|
|
|
use rand::SeedableRng;
|
|
|
|
let mut rng = IsaacRng::seed_from_u64(0);
|
2017-08-03 01:37:44 +08:00
|
|
|
let mut a = DVector::new_random(10000);
|
|
|
|
let b = DVector::new_random(10000);
|
|
|
|
let n = rng.gen::<f64>();
|
|
|
|
let beta = rng.gen::<f64>();
|
|
|
|
|
2019-03-24 01:01:04 +08:00
|
|
|
bh.bench_function("", move |bh| bh.iter(|| a.axpy(n, &b, beta)));
|
2017-08-03 01:37:44 +08:00
|
|
|
}
|
|
|
|
|
2019-03-24 01:01:04 +08:00
|
|
|
fn vec10000_axpy_f64_slice(bh: &mut criterion::Criterion) {
|
2018-12-29 19:12:56 +08:00
|
|
|
use rand::SeedableRng;
|
|
|
|
let mut rng = IsaacRng::seed_from_u64(0);
|
2017-08-03 01:37:44 +08:00
|
|
|
let mut a = DVector::new_random(10000);
|
|
|
|
let b = DVector::new_random(10000);
|
|
|
|
let n = rng.gen::<f64>();
|
|
|
|
|
2019-03-24 01:01:04 +08:00
|
|
|
bh.bench_function("", move |bh| bh.iter(|| {
|
2017-08-03 01:37:44 +08:00
|
|
|
let mut a = a.fixed_rows_mut::<U10000>(0);
|
|
|
|
let b = b.fixed_rows::<U10000>(0);
|
|
|
|
|
|
|
|
a.axpy(n, &b, 1.0)
|
2019-03-24 01:01:04 +08:00
|
|
|
}));
|
2017-08-03 01:37:44 +08:00
|
|
|
}
|
|
|
|
|
2019-03-24 01:01:04 +08:00
|
|
|
fn vec10000_axpy_f64_static(bh: &mut criterion::Criterion) {
|
2018-12-29 19:12:56 +08:00
|
|
|
use rand::SeedableRng;
|
|
|
|
let mut rng = IsaacRng::seed_from_u64(0);
|
2017-08-03 01:37:44 +08:00
|
|
|
let mut a = VectorN::<f64, U10000>::new_random();
|
|
|
|
let b = VectorN::<f64, U10000>::new_random();
|
|
|
|
let n = rng.gen::<f64>();
|
|
|
|
|
|
|
|
// NOTE: for some reasons, it is much faster if the arument are boxed (Box::new(VectorN...)).
|
2019-03-24 01:01:04 +08:00
|
|
|
bh.bench_function("", move |bh| bh.iter(|| a.axpy(n, &b, 1.0)));
|
2017-08-03 01:37:44 +08:00
|
|
|
}
|
|
|
|
|
2019-03-24 01:01:04 +08:00
|
|
|
fn vec10000_axpy_f32(bh: &mut criterion::Criterion) {
|
2018-12-29 19:12:56 +08:00
|
|
|
use rand::SeedableRng;
|
|
|
|
let mut rng = IsaacRng::seed_from_u64(0);
|
2017-08-03 01:37:44 +08:00
|
|
|
let mut a = DVector::new_random(10000);
|
|
|
|
let b = DVector::new_random(10000);
|
|
|
|
let n = rng.gen::<f32>();
|
|
|
|
|
2019-03-24 01:01:04 +08:00
|
|
|
bh.bench_function("", move |bh| bh.iter(|| a.axpy(n, &b, 1.0)));
|
2017-08-03 01:37:44 +08:00
|
|
|
}
|
|
|
|
|
2019-03-24 01:01:04 +08:00
|
|
|
fn vec10000_axpy_beta_f32(bh: &mut criterion::Criterion) {
|
2018-12-29 19:12:56 +08:00
|
|
|
use rand::SeedableRng;
|
|
|
|
let mut rng = IsaacRng::seed_from_u64(0);
|
2017-08-03 01:37:44 +08:00
|
|
|
let mut a = DVector::new_random(10000);
|
|
|
|
let b = DVector::new_random(10000);
|
|
|
|
let n = rng.gen::<f32>();
|
|
|
|
let beta = rng.gen::<f32>();
|
|
|
|
|
2019-03-24 01:01:04 +08:00
|
|
|
bh.bench_function("", move |bh| bh.iter(|| a.axpy(n, &b, beta)));
|
2017-08-03 01:37:44 +08:00
|
|
|
}
|
2019-03-24 01:01:04 +08:00
|
|
|
|
|
|
|
criterion_group!(vector, vec10000_axpy_f64_static);
|