Skip to content

Commit

Permalink
std: add #[bench] benchmarks for rand.
Browse files Browse the repository at this point in the history
  • Loading branch information
graydon committed Jul 22, 2013
1 parent 3d5fb47 commit d977623
Showing 1 changed file with 35 additions and 1 deletion.
36 changes: 35 additions & 1 deletion src/libstd/rand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -890,7 +890,7 @@ pub fn random<T: Rand>() -> T {
}

#[cfg(test)]
mod tests {
mod test {
use option::{Option, Some};
use super::*;

Expand Down Expand Up @@ -1109,3 +1109,37 @@ mod tests {
}
}
}

#[cfg(test)]
mod bench {
use extra::test::BenchHarness;
use rand::*;
use sys::size_of;

#[bench]
fn rand_xorshift(bh: &mut BenchHarness) {
let mut rng = XorShiftRng::new();
do bh.iter {
rng.gen::<uint>();
}
bh.bytes = size_of::<uint>() as u64;
}

#[bench]
fn rand_isaac(bh: &mut BenchHarness) {
let mut rng = IsaacRng::new();
do bh.iter {
rng.gen::<uint>();
}
bh.bytes = size_of::<uint>() as u64;
}

#[bench]
fn rand_shuffle_100(bh: &mut BenchHarness) {
let mut rng = XorShiftRng::new();
let x : &mut[uint] = [1,..100];
do bh.iter {
rng.shuffle_mut(x);
}
}
}

0 comments on commit d977623

Please sign in to comment.