Skip to content

Commit 83aa1ab

Browse files
committed
std::rand: lengthen the RNG benchmarks.
This makes them more representative, as the `bh.iter` is a smaller percentage of the total time.
1 parent ed5f2d7 commit 83aa1ab

File tree

1 file changed

+20
-8
lines changed

1 file changed

+20
-8
lines changed

src/libstd/rand/mod.rs

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -970,41 +970,53 @@ mod bench {
970970
use extra::test::BenchHarness;
971971
use rand::*;
972972
use mem::size_of;
973+
use iter::range;
974+
use option::{Some, None};
975+
976+
static N: u64 = 100;
973977

974978
#[bench]
975979
fn rand_xorshift(bh: &mut BenchHarness) {
976980
let mut rng = XorShiftRng::new();
977981
do bh.iter {
978-
rng.gen::<uint>();
982+
for _ in range(0, N) {
983+
rng.gen::<uint>();
984+
}
979985
}
980-
bh.bytes = size_of::<uint>() as u64;
986+
bh.bytes = size_of::<uint>() as u64 * N;
981987
}
982988

983989
#[bench]
984990
fn rand_isaac(bh: &mut BenchHarness) {
985991
let mut rng = IsaacRng::new();
986992
do bh.iter {
987-
rng.gen::<uint>();
993+
for _ in range(0, N) {
994+
rng.gen::<uint>();
995+
}
988996
}
989-
bh.bytes = size_of::<uint>() as u64;
997+
bh.bytes = size_of::<uint>() as u64 * N;
990998
}
991999

9921000
#[bench]
9931001
fn rand_isaac64(bh: &mut BenchHarness) {
9941002
let mut rng = Isaac64Rng::new();
9951003
do bh.iter {
996-
rng.gen::<uint>();
1004+
for _ in range(0, N) {
1005+
rng.gen::<uint>();
1006+
}
9971007
}
998-
bh.bytes = size_of::<uint>() as u64;
1008+
bh.bytes = size_of::<uint>() as u64 * N;
9991009
}
10001010

10011011
#[bench]
10021012
fn rand_std(bh: &mut BenchHarness) {
10031013
let mut rng = StdRng::new();
10041014
do bh.iter {
1005-
rng.gen::<uint>();
1015+
for _ in range(0, N) {
1016+
rng.gen::<uint>();
1017+
}
10061018
}
1007-
bh.bytes = size_of::<uint>() as u64;
1019+
bh.bytes = size_of::<uint>() as u64 * N;
10081020
}
10091021

10101022
#[bench]

0 commit comments

Comments
 (0)