auto merge of #16651 : vks/rust/fix-bitv-bench, r=alexcrichton

Fixes #12118.

(I sneaked in an unrelated one-character whitespace fix I spotted while reviewing some benchmarks, if that is not okay, I can create a separate pull request for that.)
This commit is contained in:
bors 2014-08-22 17:05:48 +00:00
commit 58bb603ea7
2 changed files with 30 additions and 15 deletions

View File

@ -563,7 +563,7 @@ pub fn bench_copy_old_arena(b: &mut Bencher) {
struct Noncopy {
string: String,
array: Vec<int> ,
array: Vec<int>,
}
#[test]

View File

@ -2566,7 +2566,9 @@ fn bench_uint_small(b: &mut Bencher) {
let mut r = rng();
let mut bitv = 0 as uint;
b.iter(|| {
bitv |= 1 << ((r.next_u32() as uint) % uint::BITS);
for _ in range(0u, 100) {
bitv |= 1 << ((r.next_u32() as uint) % uint::BITS);
}
&bitv
})
}
@ -2576,7 +2578,9 @@ fn bench_bitv_big(b: &mut Bencher) {
let mut r = rng();
let mut bitv = Bitv::with_capacity(BENCH_BITS, false);
b.iter(|| {
bitv.set((r.next_u32() as uint) % BENCH_BITS, true);
for _ in range(0u, 100) {
bitv.set((r.next_u32() as uint) % BENCH_BITS, true);
}
&bitv
})
}
@ -2586,7 +2590,9 @@ fn bench_bitv_small(b: &mut Bencher) {
let mut r = rng();
let mut bitv = Bitv::with_capacity(uint::BITS, false);
b.iter(|| {
bitv.set((r.next_u32() as uint) % uint::BITS, true);
for _ in range(0u, 100) {
bitv.set((r.next_u32() as uint) % uint::BITS, true);
}
&bitv
})
}
@ -2596,7 +2602,9 @@ fn bench_bitv_set_small(b: &mut Bencher) {
let mut r = rng();
let mut bitv = BitvSet::new();
b.iter(|| {
bitv.insert((r.next_u32() as uint) % uint::BITS);
for _ in range(0u, 100) {
bitv.insert((r.next_u32() as uint) % uint::BITS);
}
&bitv
})
}
@ -2606,7 +2614,9 @@ fn bench_bitv_set_big(b: &mut Bencher) {
let mut r = rng();
let mut bitv = BitvSet::new();
b.iter(|| {
bitv.insert((r.next_u32() as uint) % BENCH_BITS);
for _ in range(0u, 100) {
bitv.insert((r.next_u32() as uint) % BENCH_BITS);
}
&bitv
})
}
@ -2616,18 +2626,21 @@ fn bench_bitv_big_union(b: &mut Bencher) {
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;
for pres in bitv.iter() {
_sum += pres as uint;
let mut sum = 0;
for _ in range(0u, 10) {
for pres in bitv.iter() {
sum += pres as uint;
}
}
sum
})
}
@ -2635,10 +2648,11 @@ fn bench_btv_small_iter(b: &mut Bencher) {
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
})
}
@ -2647,10 +2661,11 @@ fn bench_bitvset_iter(b: &mut Bencher) {
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
})
}
}