Skip to content

Commit fd757a8

Browse files
committed
Added bitv iterator benchmarks
1 parent 0b4d8d6 commit fd757a8

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

src/libextra/bitv.rs

+36
Original file line numberDiff line numberDiff line change
@@ -568,6 +568,7 @@ pub struct BitvIterator<'self> {
568568
}
569569

570570
impl<'self> Iterator<bool> for BitvIterator<'self> {
571+
#[inline]
571572
fn next(&mut self) -> Option<bool> {
572573
if self.next_idx < self.bitv.nbits {
573574
let idx = self.next_idx;
@@ -866,6 +867,7 @@ pub struct BitvSetIterator<'self> {
866867
}
867868

868869
impl<'self> Iterator<uint> for BitvSetIterator<'self> {
870+
#[inline]
869871
fn next(&mut self) -> Option<uint> {
870872
while self.next_idx < self.set.capacity() {
871873
let idx = self.next_idx;
@@ -1566,4 +1568,38 @@ mod tests {
15661568
b1.union(&b2);
15671569
}
15681570
}
1571+
1572+
#[bench]
1573+
fn bench_btv_small_iter(b: &mut BenchHarness) {
1574+
let bitv = Bitv::new(uint::bits, false);
1575+
do b.iter {
1576+
let mut sum = 0;
1577+
for bitv.iter().advance |pres| {
1578+
sum += pres as uint;
1579+
}
1580+
}
1581+
}
1582+
1583+
#[bench]
1584+
fn bench_bitv_big_iter(b: &mut BenchHarness) {
1585+
let bitv = Bitv::new(BENCH_BITS, false);
1586+
do b.iter {
1587+
let mut sum = 0;
1588+
for bitv.iter().advance |pres| {
1589+
sum += pres as uint;
1590+
}
1591+
}
1592+
}
1593+
1594+
#[bench]
1595+
fn bench_bitvset_iter(b: &mut BenchHarness) {
1596+
let bitv = BitvSet::from_bitv(from_fn(BENCH_BITS,
1597+
|idx| {idx % 3 == 0}));
1598+
do b.iter {
1599+
let mut sum = 0;
1600+
for bitv.iter().advance |idx| {
1601+
sum += idx;
1602+
}
1603+
}
1604+
}
15691605
}

0 commit comments

Comments
 (0)