Skip to content

Commit d977623

Browse files
committed
std: add #[bench] benchmarks for rand.
1 parent 3d5fb47 commit d977623

File tree

1 file changed

+35
-1
lines changed

1 file changed

+35
-1
lines changed

src/libstd/rand.rs

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -890,7 +890,7 @@ pub fn random<T: Rand>() -> T {
890890
}
891891

892892
#[cfg(test)]
893-
mod tests {
893+
mod test {
894894
use option::{Option, Some};
895895
use super::*;
896896

@@ -1109,3 +1109,37 @@ mod tests {
11091109
}
11101110
}
11111111
}
1112+
1113+
#[cfg(test)]
1114+
mod bench {
1115+
use extra::test::BenchHarness;
1116+
use rand::*;
1117+
use sys::size_of;
1118+
1119+
#[bench]
1120+
fn rand_xorshift(bh: &mut BenchHarness) {
1121+
let mut rng = XorShiftRng::new();
1122+
do bh.iter {
1123+
rng.gen::<uint>();
1124+
}
1125+
bh.bytes = size_of::<uint>() as u64;
1126+
}
1127+
1128+
#[bench]
1129+
fn rand_isaac(bh: &mut BenchHarness) {
1130+
let mut rng = IsaacRng::new();
1131+
do bh.iter {
1132+
rng.gen::<uint>();
1133+
}
1134+
bh.bytes = size_of::<uint>() as u64;
1135+
}
1136+
1137+
#[bench]
1138+
fn rand_shuffle_100(bh: &mut BenchHarness) {
1139+
let mut rng = XorShiftRng::new();
1140+
let x : &mut[uint] = [1,..100];
1141+
do bh.iter {
1142+
rng.shuffle_mut(x);
1143+
}
1144+
}
1145+
}

0 commit comments

Comments
 (0)