Skip to content

Fix bitv bench #16651

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 22, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/libarena/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,7 @@ mod tests {

struct Noncopy {
string: String,
array: Vec<int> ,
array: Vec<int>,
}

#[test]
Expand Down
43 changes: 29 additions & 14 deletions src/libcollections/bitv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2566,7 +2566,9 @@ mod tests {
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
})
}
Expand All @@ -2576,7 +2578,9 @@ mod tests {
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
})
}
Expand All @@ -2586,7 +2590,9 @@ mod tests {
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
})
}
Expand All @@ -2596,7 +2602,9 @@ mod tests {
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
})
}
Expand All @@ -2606,7 +2614,9 @@ mod tests {
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
})
}
Expand All @@ -2616,29 +2626,33 @@ 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;
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
})
}

#[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 +2661,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
})
}
}