forked from dimforge/nalgebra
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
More unsafe indexing in inner loops and add some benchmarks.
- Loading branch information
Showing
10 changed files
with
288 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,164 @@ | ||
use std::rand::random; | ||
use extra::test::BenchHarness; | ||
use mat::*; | ||
use vec::*; | ||
|
||
macro_rules! bench_mul_mat( | ||
($bh: expr, $t: ty) => { | ||
{ | ||
let a: $t = random(); | ||
let mut b: $t = random(); | ||
|
||
do $bh.iter { | ||
do 1000.times { | ||
b = a * b; | ||
} | ||
} | ||
} | ||
} | ||
) | ||
|
||
#[bench] | ||
fn bench_mul_mat2(bh: &mut BenchHarness) { | ||
bench_mul_mat!(bh, Mat2<f64>) | ||
} | ||
|
||
#[bench] | ||
fn bench_mul_mat3(bh: &mut BenchHarness) { | ||
bench_mul_mat!(bh, Mat3<f64>) | ||
} | ||
|
||
#[bench] | ||
fn bench_mul_mat4(bh: &mut BenchHarness) { | ||
bench_mul_mat!(bh, Mat4<f64>) | ||
} | ||
|
||
#[bench] | ||
fn bench_mul_mat5(bh: &mut BenchHarness) { | ||
bench_mul_mat!(bh, Mat5<f64>) | ||
} | ||
|
||
#[bench] | ||
fn bench_mul_mat6(bh: &mut BenchHarness) { | ||
bench_mul_mat!(bh, Mat6<f64>) | ||
} | ||
|
||
macro_rules! bench_mul_dmat( | ||
($bh: expr, $nrows: expr, $ncols: expr) => { | ||
{ | ||
let a: DMat<f64> = DMat::new_random($nrows, $ncols); | ||
let mut b: DMat<f64> = DMat::new_random($nrows, $ncols); | ||
|
||
do $bh.iter { | ||
do 1000.times { | ||
b = a * b; | ||
} | ||
} | ||
} | ||
} | ||
) | ||
|
||
#[bench] | ||
fn bench_mul_dmat2(bh: &mut BenchHarness) { | ||
bench_mul_dmat!(bh, 2, 2) | ||
} | ||
|
||
#[bench] | ||
fn bench_mul_dmat3(bh: &mut BenchHarness) { | ||
bench_mul_dmat!(bh, 3, 3) | ||
} | ||
|
||
#[bench] | ||
fn bench_mul_dmat4(bh: &mut BenchHarness) { | ||
bench_mul_dmat!(bh, 4, 4) | ||
} | ||
|
||
#[bench] | ||
fn bench_mul_dmat5(bh: &mut BenchHarness) { | ||
bench_mul_dmat!(bh, 5, 5) | ||
} | ||
|
||
#[bench] | ||
fn bench_mul_dmat6(bh: &mut BenchHarness) { | ||
bench_mul_dmat!(bh, 6, 6) | ||
} | ||
|
||
macro_rules! bench_mul_mat_vec( | ||
($bh: expr, $tm: ty, $tv: ty) => { | ||
{ | ||
let m : $tm = random(); | ||
let mut v : $tv = random(); | ||
|
||
do $bh.iter { | ||
do 1000.times { | ||
v = m.rmul(&v) | ||
} | ||
} | ||
} | ||
} | ||
) | ||
|
||
#[bench] | ||
fn bench_mul_mat_vec2(bh: &mut BenchHarness) { | ||
bench_mul_mat_vec!(bh, Mat2<f64>, Vec2<f64>) | ||
} | ||
|
||
#[bench] | ||
fn bench_mul_mat_vec3(bh: &mut BenchHarness) { | ||
bench_mul_mat_vec!(bh, Mat3<f64>, Vec3<f64>) | ||
} | ||
|
||
#[bench] | ||
fn bench_mul_mat_vec4(bh: &mut BenchHarness) { | ||
bench_mul_mat_vec!(bh, Mat4<f64>, Vec4<f64>) | ||
} | ||
|
||
#[bench] | ||
fn bench_mul_mat_vec5(bh: &mut BenchHarness) { | ||
bench_mul_mat_vec!(bh, Mat5<f64>, Vec5<f64>) | ||
} | ||
|
||
#[bench] | ||
fn bench_mul_mat_vec6(bh: &mut BenchHarness) { | ||
bench_mul_mat_vec!(bh, Mat6<f64>, Vec6<f64>) | ||
} | ||
|
||
macro_rules! bench_mul_dmat_dvec( | ||
($bh: expr, $nrows: expr, $ncols: expr) => { | ||
{ | ||
let m : DMat<f64> = DMat::new_random($nrows, $ncols); | ||
let mut v : DVec<f64> = DVec::new_random($ncols); | ||
|
||
do $bh.iter { | ||
do 1000.times { | ||
v = m.rmul(&v) | ||
} | ||
} | ||
} | ||
} | ||
) | ||
|
||
#[bench] | ||
fn bench_mul_dmat_dvec2(bh: &mut BenchHarness) { | ||
bench_mul_dmat_dvec!(bh, 2, 2) | ||
} | ||
|
||
#[bench] | ||
fn bench_mul_dmat_dvec3(bh: &mut BenchHarness) { | ||
bench_mul_dmat_dvec!(bh, 3, 3) | ||
} | ||
|
||
#[bench] | ||
fn bench_mul_dmat_dvec4(bh: &mut BenchHarness) { | ||
bench_mul_dmat_dvec!(bh, 4, 4) | ||
} | ||
|
||
#[bench] | ||
fn bench_mul_dmat_dvec5(bh: &mut BenchHarness) { | ||
bench_mul_dmat_dvec!(bh, 5, 5) | ||
} | ||
|
||
#[bench] | ||
fn bench_mul_dmat_dvec6(bh: &mut BenchHarness) { | ||
bench_mul_dmat_dvec!(bh, 6, 6) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
use std::rand::random; | ||
use extra::test::BenchHarness; | ||
use vec::*; | ||
|
||
macro_rules! bench_dot_vec( | ||
($bh: expr, $t: ty) => { | ||
{ | ||
let a: $t = random(); | ||
let b: $t = random(); | ||
let mut d = 0.0; | ||
|
||
do $bh.iter { | ||
do 1000.times { | ||
d = d + a.dot(&b); | ||
} | ||
} | ||
} | ||
} | ||
) | ||
|
||
#[bench] | ||
fn bench_dot_vec2(bh: &mut BenchHarness) { | ||
bench_dot_vec!(bh, Vec2<f64>) | ||
} | ||
|
||
#[bench] | ||
fn bench_dot_vec3(bh: &mut BenchHarness) { | ||
bench_dot_vec!(bh, Vec3<f64>) | ||
} | ||
|
||
#[bench] | ||
fn bench_dot_vec4(bh: &mut BenchHarness) { | ||
bench_dot_vec!(bh, Vec4<f64>) | ||
} | ||
|
||
#[bench] | ||
fn bench_dot_vec5(bh: &mut BenchHarness) { | ||
bench_dot_vec!(bh, Vec5<f64>) | ||
} | ||
|
||
#[bench] | ||
fn bench_dot_vec6(bh: &mut BenchHarness) { | ||
bench_dot_vec!(bh, Vec6<f64>) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -76,5 +76,10 @@ pub mod traits { | |
mod tests { | ||
mod mat; | ||
mod vec; | ||
// mod bench; | ||
} | ||
|
||
#[cfg(test)] | ||
mod bench { | ||
mod mat; | ||
mod vec; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.