Created
September 3, 2015 21:06
-
-
Save zslayton/854e6ef8c37b272820cd to your computer and use it in GitHub Desktop.
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(test)] | |
extern crate test; | |
#[cfg(test)] | |
mod tests { | |
use test::black_box; | |
use test::Bencher; | |
const ITERATIONS: usize = 100_000; | |
struct CompoundValue { | |
pub a: u64, | |
pub b: u64, | |
pub c: u64, | |
pub d: u64, | |
pub e: u64, | |
} | |
#[bench] | |
fn bench_in_place(b: &mut Bencher) { | |
let mut compound_value = CompoundValue { | |
a: 0, | |
b: 2, | |
c: 0, | |
d: 5, | |
e: 0 | |
}; | |
let val: &mut CompoundValue = &mut compound_value; | |
let result = b.iter(|| { | |
let mut f : u64 = black_box(0); | |
for _ in 0..ITERATIONS { | |
f += val.a + val.b + val.c + val.d + val.e; | |
} | |
f = black_box(f); | |
return f; | |
}); | |
assert_eq!((), result); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment