commit
2fe17066b2
13 changed files with 345 additions and 362 deletions
|
@ -20,7 +20,7 @@ env:
|
|||
script:
|
||||
- cargo build
|
||||
- cargo test
|
||||
- make -C bench
|
||||
- cargo bench
|
||||
- cargo doc
|
||||
after_script:
|
||||
# the doc directory needs to be in the root for rust-ci
|
||||
|
|
|
@ -1,11 +0,0 @@
|
|||
all: bench
|
||||
|
||||
bench: *.rs ../src/*.rs
|
||||
(cd .. && cargo build)
|
||||
rustc -L ../target --test bench.rs
|
||||
|
||||
run: bench
|
||||
./bench --bench
|
||||
|
||||
clean:
|
||||
rm bench
|
|
@ -1,39 +0,0 @@
|
|||
// Copyright 2013 The CGMath Developers. For a full listing of the authors,
|
||||
// refer to the AUTHORS file at the top-level directory of this distribution.
|
||||
//
|
||||
// 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.
|
||||
#![feature(globs)]
|
||||
|
||||
extern crate cgmath;
|
||||
extern crate test;
|
||||
|
||||
// pub mod array;
|
||||
pub mod matrix;
|
||||
// pub mod quaternion;
|
||||
//pub mod vector;
|
||||
|
||||
//pub mod angle;
|
||||
//pub mod plane;
|
||||
//pub mod point;
|
||||
// pub mod ray;
|
||||
// pub mod rotation;
|
||||
//pub mod transform;
|
||||
|
||||
// pub mod projection;
|
||||
|
||||
// pub mod aabb;
|
||||
// pub mod cylinder;
|
||||
// pub mod frustum;
|
||||
// pub mod intersect;
|
||||
// pub mod obb;
|
||||
//pub mod sphere;
|
304
bench/matrix.rs
304
bench/matrix.rs
|
@ -1,304 +0,0 @@
|
|||
// Copyright 2013 The CGMath Developers. For a full listing of the authors,
|
||||
// refer to the AUTHORS file at the top-level directory of this distribution.
|
||||
//
|
||||
// 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.
|
||||
|
||||
use cgmath::*;
|
||||
|
||||
use test::Bencher;
|
||||
|
||||
pub mod matrix2 {
|
||||
use cgmath::*;
|
||||
|
||||
pub static A: Matrix2<f32> = Matrix2 { x: Vector2 { x: 1.0, y: 3.0 },
|
||||
y: Vector2 { x: 2.0, y: 4.0 } };
|
||||
pub static B: Matrix2<f32> = Matrix2 { x: Vector2 { x: 2.0, y: 4.0 },
|
||||
y: Vector2 { x: 3.0, y: 5.0 } };
|
||||
}
|
||||
|
||||
pub mod matrix3 {
|
||||
use cgmath::*;
|
||||
|
||||
pub static A: Matrix3<f32> = Matrix3 { x: Vector3 { x: 1.0, y: 4.0, z: 7.0 },
|
||||
y: Vector3 { x: 2.0, y: 5.0, z: 8.0 },
|
||||
z: Vector3 { x: 3.0, y: 6.0, z: 9.0 } };
|
||||
pub static B: Matrix3<f32> = Matrix3 { x: Vector3 { x: 2.0, y: 5.0, z: 8.0 },
|
||||
y: Vector3 { x: 3.0, y: 6.0, z: 9.0 },
|
||||
z: Vector3 { x: 4.0, y: 7.0, z: 10.0 } };
|
||||
}
|
||||
|
||||
pub mod matrix4 {
|
||||
use cgmath::*;
|
||||
|
||||
pub static A: Matrix4<f32> = Matrix4 { x: Vector4 { x: 1.0, y: 5.0, z: 9.0, w: 13.0 },
|
||||
y: Vector4 { x: 2.0, y: 6.0, z: 10.0, w: 14.0 },
|
||||
z: Vector4 { x: 3.0, y: 7.0, z: 11.0, w: 15.0 },
|
||||
w: Vector4 { x: 4.0, y: 8.0, z: 12.0, w: 16.0 } };
|
||||
pub static B: Matrix4<f32> = Matrix4 { x: Vector4 { x: 2.0, y: 6.0, z: 10.0, w: 14.0 },
|
||||
y: Vector4 { x: 3.0, y: 7.0, z: 11.0, w: 15.0 },
|
||||
z: Vector4 { x: 4.0, y: 8.0, z: 12.0, w: 16.0 },
|
||||
w: Vector4 { x: 5.0, y: 9.0, z: 13.0, w: 17.0 } };
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_matrix2_mul_m(b: &mut Bencher) {
|
||||
let mut matrix_a = matrix2::A.clone();
|
||||
b.iter(|| { matrix_a = matrix_a.mul_m(&matrix2::B); })
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_matrix3_mul_m(b: &mut Bencher) {
|
||||
let mut matrix_a = matrix3::A.clone();
|
||||
b.iter(|| { matrix_a = matrix_a.mul_m(&matrix3::B); })
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_matrix4_mul_m(b: &mut Bencher) {
|
||||
let mut matrix_a = matrix4::A.clone();
|
||||
b.iter(|| { matrix_a = matrix_a.mul_m(&matrix4::B); })
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_matrix2_add_m(b: &mut Bencher) {
|
||||
let mut matrix_a = matrix2::A.clone();
|
||||
b.iter(|| { matrix_a = matrix_a.add_m(&matrix2::B); })
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_matrix3_add_m(b: &mut Bencher) {
|
||||
let mut matrix_a = matrix3::A.clone();
|
||||
b.iter(|| { matrix_a = matrix_a.add_m(&matrix3::B); })
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_matrix4_add_m(b: &mut Bencher) {
|
||||
let mut matrix_a = matrix4::A.clone();
|
||||
b.iter(|| { matrix_a = matrix_a.add_m(&matrix4::B); })
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_matrix2_sub_m(b: &mut Bencher) {
|
||||
let mut matrix_a = matrix2::A.clone();
|
||||
b.iter(|| { matrix_a = matrix_a.sub_m(&matrix2::B); })
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_matrix3_sub_m(b: &mut Bencher) {
|
||||
let mut matrix_a = matrix3::A.clone();
|
||||
b.iter(|| { matrix_a = matrix_a.sub_m(&matrix3::B); })
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_matrix4_sub_m(b: &mut Bencher) {
|
||||
let mut matrix_a = matrix4::A.clone();
|
||||
b.iter(|| { matrix_a = matrix_a.sub_m(&matrix4::B); })
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_matrix2_mul_s(b: &mut Bencher) {
|
||||
let mut matrix_a = matrix2::A.clone();
|
||||
b.iter(|| { matrix_a = matrix_a.mul_s(2.0); })
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_matrix3_mul_s(b: &mut Bencher) {
|
||||
let mut matrix_a = matrix3::A.clone();
|
||||
b.iter(|| { matrix_a = matrix_a.mul_s(2.0); })
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_matrix4_mul_s(b: &mut Bencher) {
|
||||
let mut matrix_a = matrix4::A.clone();
|
||||
b.iter(|| { matrix_a = matrix_a.mul_s(2.0); })
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_matrix2_div_s(b: &mut Bencher) {
|
||||
let mut matrix_a = matrix2::A.clone();
|
||||
b.iter(|| { matrix_a = matrix_a.div_s(2.); })
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_matrix3_div_s(b: &mut Bencher) {
|
||||
let mut matrix_a = matrix3::A.clone();
|
||||
b.iter(|| { matrix_a = matrix_a.div_s(2.); })
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_matrix4_div_s(b: &mut Bencher) {
|
||||
let mut matrix_a = matrix4::A.clone();
|
||||
b.iter(|| { matrix_a = matrix_a.div_s(2.); })
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_matrix2_rem_s(b: &mut Bencher) {
|
||||
let mut matrix_a = matrix2::A.clone();
|
||||
b.iter(|| { matrix_a = matrix_a.rem_s(2.); })
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_matrix3_rem_s(b: &mut Bencher) {
|
||||
let mut matrix_a = matrix3::A.clone();
|
||||
b.iter(|| { matrix_a = matrix_a.rem_s(2.); })
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_matrix4_rem_s(b: &mut Bencher) {
|
||||
let mut matrix_a = matrix4::A.clone();
|
||||
b.iter(|| { matrix_a = matrix_a.rem_s(2.); })
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_matrix2_neg_self(b: &mut Bencher) {
|
||||
let mut matrix_a = matrix2::A.clone();
|
||||
b.iter(|| { matrix_a.neg_self(); })
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_matrix3_neg_self(b: &mut Bencher) {
|
||||
let mut matrix_a = matrix3::A.clone();
|
||||
b.iter(|| { matrix_a.neg_self(); })
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_matrix4_neg_self(b: &mut Bencher) {
|
||||
let mut matrix_a = matrix4::A.clone();
|
||||
b.iter(|| { matrix_a.neg_self(); })
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_matrix2_div_self_s(b: &mut Bencher) {
|
||||
let mut matrix_a = matrix2::A.clone();
|
||||
b.iter(|| { matrix_a.div_self_s(2.); })
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_matrix3_div_self_s(b: &mut Bencher) {
|
||||
let mut matrix_a = matrix3::A.clone();
|
||||
b.iter(|| { matrix_a.div_self_s(2.); })
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_matrix4_div_self_s(b: &mut Bencher) {
|
||||
let mut matrix_a = matrix4::A.clone();
|
||||
b.iter(|| { matrix_a.div_self_s(2.); })
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_matrix2_rem_self_s(b: &mut Bencher) {
|
||||
let mut matrix_a = matrix2::A.clone();
|
||||
b.iter(|| { matrix_a.rem_self_s(2.); })
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_matrix3_rem_self_s(b: &mut Bencher) {
|
||||
let mut matrix_a = matrix3::A.clone();
|
||||
b.iter(|| { matrix_a.rem_self_s(2.); })
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_matrix4_rem_self_s(b: &mut Bencher) {
|
||||
let mut matrix_a = matrix4::A.clone();
|
||||
b.iter(|| { matrix_a.rem_self_s(2.); })
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_matrix2_mul_self_m(b: &mut Bencher) {
|
||||
let mut matrix_a = matrix2::A.clone();
|
||||
b.iter(|| { matrix_a.mul_self_m(&matrix2::B); })
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_matrix3_mul_self_m(b: &mut Bencher) {
|
||||
let mut matrix_a = matrix3::A.clone();
|
||||
b.iter(|| { matrix_a.mul_self_m(&matrix3::B); })
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_matrix4_mul_self_m(b: &mut Bencher) {
|
||||
let mut matrix_a = matrix4::A.clone();
|
||||
b.iter(|| { matrix_a.mul_self_m(&matrix4::B); })
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_matrix2_add_self_m(b: &mut Bencher) {
|
||||
let mut matrix_a = matrix2::A.clone();
|
||||
b.iter(|| { matrix_a.add_self_m(&matrix2::B); })
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_matrix3_add_self_m(b: &mut Bencher) {
|
||||
let mut matrix_a = matrix3::A.clone();
|
||||
b.iter(|| { matrix_a.add_self_m(&matrix3::B); })
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_matrix4_add_self_m(b: &mut Bencher) {
|
||||
let mut matrix_a = matrix4::A.clone();
|
||||
b.iter(|| { matrix_a.add_self_m(&matrix4::B); })
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_matrix2_sub_self_m(b: &mut Bencher) {
|
||||
let mut matrix_a = matrix2::A.clone();
|
||||
b.iter(|| { matrix_a.sub_self_m(&matrix2::B); })
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_matrix3_sub_self_m(b: &mut Bencher) {
|
||||
let mut matrix_a = matrix3::A.clone();
|
||||
b.iter(|| { matrix_a.sub_self_m(&matrix3::B); })
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_matrix4_sub_self_m(b: &mut Bencher) {
|
||||
let mut matrix_a = matrix4::A.clone();
|
||||
b.iter(|| { matrix_a.add_self_m(&matrix4::B); })
|
||||
}
|
||||
|
||||
|
||||
#[bench]
|
||||
fn bench_matrix2_transpose(b: &mut Bencher) {
|
||||
let mut matrix_a = matrix2::A.clone();
|
||||
b.iter(|| { matrix_a = matrix_a.transpose(); })
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_matrix3_transpose(b: &mut Bencher) {
|
||||
let mut matrix_a = matrix3::A.clone();
|
||||
b.iter(|| { matrix_a = matrix_a.transpose(); })
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_matrix4_transpose(b: &mut Bencher) {
|
||||
let mut matrix_a = matrix4::A.clone();
|
||||
b.iter(|| { matrix_a = matrix_a.transpose(); })
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_matrix2_transpose_self(b: &mut Bencher) {
|
||||
let mut matrix_a = matrix2::A.clone();
|
||||
b.iter(|| { matrix_a.transpose_self(); })
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_matrix3_transpose_self(b: &mut Bencher) {
|
||||
let mut matrix_a = matrix3::A.clone();
|
||||
b.iter(|| { matrix_a.transpose_self(); })
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_matrix4_transpose_self(b: &mut Bencher) {
|
||||
let mut matrix_a = matrix4::A.clone();
|
||||
b.iter(|| { matrix_a.transpose_self(); })
|
||||
}
|
107
benches/common/macros.rs
Normal file
107
benches/common/macros.rs
Normal file
|
@ -0,0 +1,107 @@
|
|||
// Copyright 2013-2014 The CGMath Developers. For a full listing of the authors,
|
||||
// refer to the AUTHORS file at the top-level directionectory of this distribution.
|
||||
//
|
||||
// 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.
|
||||
|
||||
#![macro_escape]
|
||||
|
||||
macro_rules! bench_binop(
|
||||
($name: ident, $t1: ty, $t2: ty, $binop: ident) => {
|
||||
#[bench]
|
||||
fn $name(bh: &mut Bencher) {
|
||||
const LEN: uint = 1 << 13;
|
||||
|
||||
let mut rng = IsaacRng::new_unseeded();
|
||||
|
||||
let elems1 = Vec::from_fn(LEN, |_| rng.gen::<$t1>());
|
||||
let elems2 = Vec::from_fn(LEN, |_| rng.gen::<$t2>());
|
||||
let mut i = 0;
|
||||
|
||||
bh.iter(|| {
|
||||
i = (i + 1) & (LEN - 1);
|
||||
|
||||
unsafe {
|
||||
test::black_box(elems1.unsafe_get(i).$binop(elems2.unsafe_get(i)))
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
macro_rules! bench_binop_deref(
|
||||
($name: ident, $t1: ty, $t2: ty, $binop: ident) => {
|
||||
#[bench]
|
||||
fn $name(bh: &mut Bencher) {
|
||||
const LEN: uint = 1 << 13;
|
||||
|
||||
let mut rng = IsaacRng::new_unseeded();
|
||||
|
||||
let elems1 = Vec::from_fn(LEN, |_| rng.gen::<$t1>());
|
||||
let elems2 = Vec::from_fn(LEN, |_| rng.gen::<$t2>());
|
||||
let mut i = 0;
|
||||
|
||||
bh.iter(|| {
|
||||
i = (i + 1) & (LEN - 1);
|
||||
|
||||
unsafe {
|
||||
test::black_box(elems1.unsafe_get(i).$binop(*elems2.unsafe_get(i)))
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
macro_rules! bench_unop(
|
||||
($name: ident, $t: ty, $unop: ident) => {
|
||||
#[bench]
|
||||
fn $name(bh: &mut Bencher) {
|
||||
const LEN: uint = 1 << 13;
|
||||
|
||||
let mut rng = IsaacRng::new_unseeded();
|
||||
|
||||
let mut elems = Vec::from_fn(LEN, |_| rng.gen::<$t>());
|
||||
let mut i = 0;
|
||||
|
||||
bh.iter(|| {
|
||||
i = (i + 1) & (LEN - 1);
|
||||
|
||||
unsafe {
|
||||
test::black_box(elems.unsafe_mut(i).$unop())
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
macro_rules! bench_construction(
|
||||
($name: ident, $t: ty, $constructor: path $(, $args: ident: $types: ty)*) => {
|
||||
#[bench]
|
||||
fn $name(bh: &mut Bencher) {
|
||||
const LEN: uint = 1 << 13;
|
||||
|
||||
let mut rng = IsaacRng::new_unseeded();
|
||||
|
||||
$(let $args = Vec::from_fn(LEN, |_| rng.gen::<$types>());)*
|
||||
let mut i = 0;
|
||||
|
||||
bh.iter(|| {
|
||||
i = (i + 1) & (LEN - 1);
|
||||
|
||||
unsafe {
|
||||
let res: $t = $constructor($(*$args.unsafe_get(i),)*);
|
||||
test::black_box(res)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
)
|
60
benches/construction.rs
Normal file
60
benches/construction.rs
Normal file
|
@ -0,0 +1,60 @@
|
|||
// Copyright 2013-2014 The CGMath Developers. For a full listing of the authors,
|
||||
// refer to the AUTHORS file at the top-level directionectory of this distribution.
|
||||
//
|
||||
// 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.
|
||||
|
||||
#![feature(macro_rules)]
|
||||
|
||||
extern crate test;
|
||||
extern crate cgmath;
|
||||
|
||||
use std::rand::{IsaacRng, Rng};
|
||||
use test::Bencher;
|
||||
use cgmath::{Quaternion, Basis2, Basis3, Vector3, Rotation2, Rotation3, Rad};
|
||||
|
||||
#[path="common/macros.rs"]
|
||||
mod macros;
|
||||
|
||||
fn bench_from_axis_angle<T: Rotation3<f32>>(bh: &mut Bencher) {
|
||||
const LEN: uint = 1 << 13;
|
||||
|
||||
let mut rng = IsaacRng::new_unseeded();
|
||||
|
||||
let axis = Vec::from_fn(LEN, |_| rng.gen::<Vector3<f32>>());
|
||||
let angle = Vec::from_fn(LEN, |_| rng.gen::<Rad<f32>>());
|
||||
let mut i = 0;
|
||||
|
||||
bh.iter(|| {
|
||||
i = (i + 1) & (LEN - 1);
|
||||
|
||||
unsafe {
|
||||
let res: T = Rotation3::from_axis_angle(axis.unsafe_get(i), *angle.unsafe_get(i));
|
||||
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)
|
||||
}
|
||||
|
||||
bench_construction!(_bench_rot2_from_axisangle, Basis2<f32>, Rotation2::from_angle, angle: Rad<f32>)
|
||||
|
||||
bench_construction!(_bench_quat_from_euler_angles, Quaternion<f32>, Rotation3::from_euler, roll: Rad<f32>, pitch: Rad<f32>, yaw: Rad<f32>)
|
||||
bench_construction!(_bench_rot3_from_euler_angles, Basis3<f32>, Rotation3::from_euler, roll: Rad<f32>, pitch: Rad<f32>, yaw: Rad<f32>)
|
59
benches/mat.rs
Normal file
59
benches/mat.rs
Normal file
|
@ -0,0 +1,59 @@
|
|||
// Copyright 2013-2014 The CGMath Developers. For a full listing of the authors,
|
||||
// refer to the AUTHORS file at the top-level directionectory of this distribution.
|
||||
//
|
||||
// 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.
|
||||
|
||||
#![feature(macro_rules)]
|
||||
#![feature(globs)]
|
||||
|
||||
extern crate test;
|
||||
extern crate cgmath;
|
||||
|
||||
use std::rand::{IsaacRng, Rng};
|
||||
use test::Bencher;
|
||||
use cgmath::*;
|
||||
|
||||
#[path="common/macros.rs"]
|
||||
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_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_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_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_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_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_unop!(_bench_matrix2_invert, Matrix2<f32>, invert)
|
||||
bench_unop!(_bench_matrix3_invert, Matrix3<f32>, invert)
|
||||
bench_unop!(_bench_matrix4_invert, Matrix4<f32>, invert)
|
||||
|
||||
bench_unop!(_bench_matrix2_transpose, Matrix2<f32>, transpose)
|
||||
bench_unop!(_bench_matrix3_transpose, Matrix3<f32>, transpose)
|
||||
bench_unop!(_bench_matrix4_transpose, Matrix4<f32>, transpose)
|
37
benches/quat.rs
Normal file
37
benches/quat.rs
Normal file
|
@ -0,0 +1,37 @@
|
|||
// Copyright 2013-2014 The CGMath Developers. For a full listing of the authors,
|
||||
// refer to the AUTHORS file at the top-level directionectory of this distribution.
|
||||
//
|
||||
// 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.
|
||||
|
||||
#![feature(globs)]
|
||||
#![feature(macro_rules)]
|
||||
|
||||
extern crate test;
|
||||
extern crate cgmath;
|
||||
|
||||
use std::rand::{IsaacRng, Rng};
|
||||
use test::Bencher;
|
||||
use cgmath::*;
|
||||
|
||||
#[path="common/macros.rs"]
|
||||
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_unop!(_bench_quat_invert, Quaternion<f32>, invert)
|
||||
bench_unop!(_bench_quat_conjugate, Quaternion<f32>, conjugate)
|
||||
bench_unop!(_bench_quat_normalize, Quaternion<f32>, normalize)
|
74
benches/vec.rs
Normal file
74
benches/vec.rs
Normal file
|
@ -0,0 +1,74 @@
|
|||
// Copyright 2013-2014 The CGMath Developers. For a full listing of the authors,
|
||||
// refer to the AUTHORS file at the top-level directionectory of this distribution.
|
||||
//
|
||||
// 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.
|
||||
|
||||
#![feature(globs)]
|
||||
#![feature(macro_rules)]
|
||||
|
||||
extern crate test;
|
||||
extern crate cgmath;
|
||||
|
||||
use std::rand::{IsaacRng, Rng};
|
||||
use test::Bencher;
|
||||
use cgmath::*;
|
||||
|
||||
#[path="common/macros.rs"]
|
||||
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_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_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_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_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_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_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_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_dot, Vector2<f32>, Vector2<f32>, dot)
|
||||
bench_binop!(_bench_vector3_dot, Vector3<f32>, Vector3<f32>, dot)
|
||||
bench_binop!(_bench_vector4_dot, Vector4<f32>, Vector4<f32>, dot)
|
||||
|
||||
bench_binop!(_bench_vector3_cross, Vector3<f32>, Vector3<f32>, cross)
|
||||
|
||||
bench_unop!(_bench_vector2_norm, Vector2<f32>, length)
|
||||
bench_unop!(_bench_vector3_norm, Vector3<f32>, length)
|
||||
bench_unop!(_bench_vector4_norm, Vector4<f32>, length)
|
||||
|
||||
bench_unop!(_bench_vector2_normalize, Vector2<f32>, normalize)
|
||||
bench_unop!(_bench_vector3_normalize, Vector3<f32>, normalize)
|
||||
bench_unop!(_bench_vector4_normalize, Vector4<f32>, normalize)
|
|
@ -22,10 +22,10 @@ use approx::ApproxEq;
|
|||
use num::BaseFloat;
|
||||
|
||||
/// An angle, in radians
|
||||
#[deriving(Clone, PartialEq, PartialOrd, Hash, Encodable, Decodable)]
|
||||
#[deriving(Clone, PartialEq, PartialOrd, Hash, Encodable, Decodable, Rand)]
|
||||
pub struct Rad<S> { pub s: S }
|
||||
/// An angle, in degrees
|
||||
#[deriving(Clone, PartialEq, PartialOrd, Hash, Encodable, Decodable)]
|
||||
#[deriving(Clone, PartialEq, PartialOrd, Hash, Encodable, Decodable, Rand)]
|
||||
pub struct Deg<S> { pub s: S }
|
||||
|
||||
/// Create a new angle, in radians
|
||||
|
|
|
@ -29,15 +29,15 @@ use vector::{Vector, EuclideanVector};
|
|||
use vector::{Vector2, Vector3, Vector4};
|
||||
|
||||
/// A 2 x 2, column major matrix
|
||||
#[deriving(Clone, PartialEq, Encodable, Decodable)]
|
||||
#[deriving(Clone, PartialEq, Encodable, Decodable, Rand)]
|
||||
pub struct Matrix2<S> { pub x: Vector2<S>, pub y: Vector2<S> }
|
||||
|
||||
/// A 3 x 3, column major matrix
|
||||
#[deriving(Clone, PartialEq, Encodable, Decodable)]
|
||||
#[deriving(Clone, PartialEq, Encodable, Decodable, Rand)]
|
||||
pub struct Matrix3<S> { pub x: Vector3<S>, pub y: Vector3<S>, pub z: Vector3<S> }
|
||||
|
||||
/// A 4 x 4, column major matrix
|
||||
#[deriving(Clone, PartialEq, Encodable, Decodable)]
|
||||
#[deriving(Clone, PartialEq, Encodable, Decodable, Rand)]
|
||||
pub struct Matrix4<S> { pub x: Vector4<S>, pub y: Vector4<S>, pub z: Vector4<S>, pub w: Vector4<S> }
|
||||
|
||||
|
||||
|
|
|
@ -28,7 +28,7 @@ use vector::{Vector3, Vector, EuclideanVector};
|
|||
|
||||
/// A [quaternion](https://en.wikipedia.org/wiki/Quaternion) in scalar/vector
|
||||
/// form.
|
||||
#[deriving(Clone, PartialEq, Encodable, Decodable)]
|
||||
#[deriving(Clone, PartialEq, Encodable, Decodable, Rand)]
|
||||
pub struct Quaternion<S> { pub s: S, pub v: Vector3<S> }
|
||||
|
||||
/// Represents types which can be expressed as a quaternion.
|
||||
|
|
|
@ -183,7 +183,7 @@ pub trait Vector<S: BaseNum>: Array1<S>
|
|||
// Utility macro for generating associated functions for the vectors
|
||||
macro_rules! vec(
|
||||
($Self:ident <$S:ident> { $($field:ident),+ }, $n:expr) => (
|
||||
#[deriving(PartialEq, Eq, Clone, Hash, Encodable, Decodable)]
|
||||
#[deriving(PartialEq, Eq, Clone, Hash, Encodable, Decodable, Rand)]
|
||||
pub struct $Self<S> { $(pub $field: S),+ }
|
||||
|
||||
impl<$S> $Self<$S> {
|
||||
|
|
Loading…
Reference in a new issue