Skip to content

Commit c94bf8b

Browse files
committed
bitv: make benchmarks always return a value
This makes sure that the benchmarked code does not get optimized away. Also fixed a typo. Fixes #12118.
1 parent 6de570f commit c94bf8b

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

src/libcollections/bitv.rs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2616,29 +2616,31 @@ mod tests {
26162616
let mut b1 = Bitv::with_capacity(BENCH_BITS, false);
26172617
let b2 = Bitv::with_capacity(BENCH_BITS, false);
26182618
b.iter(|| {
2619-
b1.union(&b2);
2619+
b1.union(&b2)
26202620
})
26212621
}
26222622

26232623
#[bench]
2624-
fn bench_btv_small_iter(b: &mut Bencher) {
2624+
fn bench_bitv_small_iter(b: &mut Bencher) {
26252625
let bitv = Bitv::with_capacity(uint::BITS, false);
26262626
b.iter(|| {
2627-
let mut _sum = 0;
2627+
let mut sum = 0;
26282628
for pres in bitv.iter() {
2629-
_sum += pres as uint;
2629+
sum += pres as uint;
26302630
}
2631+
sum
26312632
})
26322633
}
26332634

26342635
#[bench]
26352636
fn bench_bitv_big_iter(b: &mut Bencher) {
26362637
let bitv = Bitv::with_capacity(BENCH_BITS, false);
26372638
b.iter(|| {
2638-
let mut _sum = 0;
2639+
let mut sum = 0;
26392640
for pres in bitv.iter() {
2640-
_sum += pres as uint;
2641+
sum += pres as uint;
26412642
}
2643+
sum
26422644
})
26432645
}
26442646

@@ -2647,10 +2649,11 @@ mod tests {
26472649
let bitv = BitvSet::from_bitv(from_fn(BENCH_BITS,
26482650
|idx| {idx % 3 == 0}));
26492651
b.iter(|| {
2650-
let mut _sum = 0;
2652+
let mut sum = 0;
26512653
for idx in bitv.iter() {
2652-
_sum += idx;
2654+
sum += idx;
26532655
}
2656+
sum
26542657
})
26552658
}
26562659
}

0 commit comments

Comments
 (0)