Created
April 13, 2015 22:16
-
-
Save haxelion/abeab65d96b20e397af3 to your computer and use it in GitHub Desktop.
SIMD test, see: http://www.reddit.com/r/rust/comments/32hl9w/more_on_the_simd_directive_and_whether_or_not_its/
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
#![feature(simd)] | |
extern crate rand; | |
extern crate time; | |
mod lin_alg; | |
use lin_alg::Quat; | |
use rand::Rng; | |
fn main(){ | |
let mut rng = rand::XorShiftRng::new_unseeded(); | |
let runs = 10000000000; | |
let mut s_time: time::Duration = time::Duration::zero(); | |
let mut f_time: time::Duration = time::Duration::zero(); | |
let rhs = Quat::new_dir(rng.gen(), rng.gen(), rng.gen()); | |
let mut lhs = Quat::new_dir(0.0, 0.0, 0.0); | |
let s_start = time::get_time(); | |
for _ in (1..runs) { | |
lhs = lhs + rhs; | |
} | |
let s_end = time::get_time(); | |
println!("Simd : {:?}", lhs); | |
lhs = Quat::new_dir(0.0, 0.0, 0.0); | |
let f_start = time::get_time(); | |
for _ in (1..runs) { | |
lhs = lhs.add(&rhs); | |
} | |
let f_end = time::get_time(); | |
println!("Func : {:?}", lhs); | |
let s_elapsed = s_end - s_start; | |
let f_elapsed = f_end - f_start; | |
s_time = s_time.checked_add(&s_elapsed).unwrap(); | |
f_time = f_time.checked_add(&f_elapsed).unwrap(); | |
let s_avg = s_time.num_nanoseconds().unwrap() as f64 / runs as f64; | |
let f_avg = f_time.num_nanoseconds().unwrap() as f64 / runs as f64; | |
println!("Time for 'simd': {:?} \nTime for func: {:?} \nDiff {:?}", s_avg, f_avg, f_avg - s_avg); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment