2014-11-07 15:13:54 +00:00
|
|
|
// Copyright 2013-2014 The CGMath Developers. For a full listing of the authors,
|
2015-03-14 02:44:59 +00:00
|
|
|
// refer to the Cargo.toml file at the top-level directory of this distribution.
|
2014-11-07 15:13:54 +00:00
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
2015-02-08 18:42:28 +00:00
|
|
|
#![feature(test)]
|
2015-01-07 22:34:42 +00:00
|
|
|
|
2018-01-03 02:01:02 +00:00
|
|
|
extern crate cgmath;
|
2015-02-08 18:42:28 +00:00
|
|
|
extern crate rand;
|
2014-11-07 15:13:54 +00:00
|
|
|
extern crate test;
|
|
|
|
|
2015-02-08 18:42:28 +00:00
|
|
|
use rand::{IsaacRng, Rng};
|
2014-11-07 15:13:54 +00:00
|
|
|
use test::Bencher;
|
2016-04-17 04:33:06 +00:00
|
|
|
use cgmath::*;
|
2014-11-07 15:13:54 +00:00
|
|
|
|
2018-01-03 02:01:02 +00:00
|
|
|
#[path = "common/macros.rs"]
|
|
|
|
#[macro_use]
|
|
|
|
mod macros;
|
2014-11-07 15:13:54 +00:00
|
|
|
|
|
|
|
fn bench_from_axis_angle<T: Rotation3<f32>>(bh: &mut Bencher) {
|
2015-01-09 23:16:39 +00:00
|
|
|
const LEN: usize = 1 << 13;
|
2014-11-07 15:13:54 +00:00
|
|
|
|
|
|
|
let mut rng = IsaacRng::new_unseeded();
|
|
|
|
|
2015-03-18 17:13:21 +00:00
|
|
|
let axis: Vec<_> = (0..LEN).map(|_| rng.gen::<Vector3<f32>>()).collect();
|
|
|
|
let angle: Vec<_> = (0..LEN).map(|_| rng.gen::<Rad<f32>>()).collect();
|
2014-11-07 15:13:54 +00:00
|
|
|
let mut i = 0;
|
|
|
|
|
|
|
|
bh.iter(|| {
|
|
|
|
i = (i + 1) & (LEN - 1);
|
|
|
|
|
|
|
|
unsafe {
|
2018-01-03 02:01:02 +00:00
|
|
|
let res: T =
|
|
|
|
Rotation3::from_axis_angle(*axis.get_unchecked(i), *angle.get_unchecked(i));
|
2014-11-07 15:13:54 +00:00
|
|
|
test::black_box(res)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
#[bench]
|
|
|
|
fn _bench_quat_from_axisangle(bh: &mut Bencher) {
|
|
|
|
bench_from_axis_angle::<Quaternion<f32>>(bh)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[bench]
|
|
|
|
fn _bench_rot3_from_axisangle(bh: &mut Bencher) {
|
|
|
|
bench_from_axis_angle::<Basis3<f32>>(bh)
|
|
|
|
}
|
|
|
|
|
2018-01-03 02:01:02 +00:00
|
|
|
bench_construction!(
|
|
|
|
_bench_rot2_from_axisangle,
|
|
|
|
Basis2<f32>,
|
|
|
|
Basis2::from_angle[angle: Rad<f32>]
|
|
|
|
);
|
2014-11-07 15:13:54 +00:00
|
|
|
|
2018-01-03 02:01:02 +00:00
|
|
|
bench_construction!(
|
|
|
|
_bench_quat_from_euler_angles,
|
|
|
|
Quaternion<f32>,
|
|
|
|
Quaternion::from[src: Euler<Rad<f32>>]
|
|
|
|
);
|
|
|
|
bench_construction!(
|
|
|
|
_bench_rot3_from_euler_angles,
|
|
|
|
Basis3<f32>,
|
|
|
|
Basis3::from[src: Euler<Rad<f32>>]
|
|
|
|
);
|