Skip to content

Commit

Permalink
bitv: make benchmarks always return a value
Browse files Browse the repository at this point in the history
This makes sure that the benchmarked code does not get optimized away.
Also fixed a typo.

Fixes #12118.
  • Loading branch information
vks committed Aug 21, 2014
1 parent 6de570f commit c94bf8b
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions src/libcollections/bitv.rs
Expand Up @@ -2616,29 +2616,31 @@ mod tests {
let mut b1 = Bitv::with_capacity(BENCH_BITS, false);
let b2 = Bitv::with_capacity(BENCH_BITS, false);
b.iter(|| {
b1.union(&b2);
b1.union(&b2)
})
}

#[bench]
fn bench_btv_small_iter(b: &mut Bencher) {
fn bench_bitv_small_iter(b: &mut Bencher) {
let bitv = Bitv::with_capacity(uint::BITS, false);
b.iter(|| {
let mut _sum = 0;
let mut sum = 0;
for pres in bitv.iter() {
_sum += pres as uint;
sum += pres as uint;
}
sum
})
}

#[bench]
fn bench_bitv_big_iter(b: &mut Bencher) {
let bitv = Bitv::with_capacity(BENCH_BITS, false);
b.iter(|| {
let mut _sum = 0;
let mut sum = 0;
for pres in bitv.iter() {
_sum += pres as uint;
sum += pres as uint;
}
sum
})
}

Expand All @@ -2647,10 +2649,11 @@ mod tests {
let bitv = BitvSet::from_bitv(from_fn(BENCH_BITS,
|idx| {idx % 3 == 0}));
b.iter(|| {
let mut _sum = 0;
let mut sum = 0;
for idx in bitv.iter() {
_sum += idx;
sum += idx;
}
sum
})
}
}

0 comments on commit c94bf8b

Please sign in to comment.