diff options
| author | Steven Fackler <sfackler@gmail.com> | 2013-07-14 11:52:49 -0700 |
|---|---|---|
| committer | Steven Fackler <sfackler@gmail.com> | 2013-07-21 03:22:59 -0400 |
| commit | fd757a8ab0f6bc84227d1ac7a83c55e09ea9dbcf (patch) | |
| tree | 5366b09d3fac58fe53bfa9fa8f7a90c11638c4c5 /src/libextra | |
| parent | 0b4d8d688240c229a4e3d51cdaa96899258a2340 (diff) | |
| download | rust-fd757a8ab0f6bc84227d1ac7a83c55e09ea9dbcf.tar.gz rust-fd757a8ab0f6bc84227d1ac7a83c55e09ea9dbcf.zip | |
Added bitv iterator benchmarks
Diffstat (limited to 'src/libextra')
| -rw-r--r-- | src/libextra/bitv.rs | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/src/libextra/bitv.rs b/src/libextra/bitv.rs index 69c851e248b..168d6a39916 100644 --- a/src/libextra/bitv.rs +++ b/src/libextra/bitv.rs @@ -568,6 +568,7 @@ pub struct BitvIterator<'self> { } impl<'self> Iterator<bool> for BitvIterator<'self> { + #[inline] fn next(&mut self) -> Option<bool> { if self.next_idx < self.bitv.nbits { let idx = self.next_idx; @@ -866,6 +867,7 @@ pub struct BitvSetIterator<'self> { } impl<'self> Iterator<uint> for BitvSetIterator<'self> { + #[inline] fn next(&mut self) -> Option<uint> { while self.next_idx < self.set.capacity() { let idx = self.next_idx; @@ -1566,4 +1568,38 @@ mod tests { b1.union(&b2); } } + + #[bench] + fn bench_btv_small_iter(b: &mut BenchHarness) { + let bitv = Bitv::new(uint::bits, false); + do b.iter { + let mut sum = 0; + for bitv.iter().advance |pres| { + sum += pres as uint; + } + } + } + + #[bench] + fn bench_bitv_big_iter(b: &mut BenchHarness) { + let bitv = Bitv::new(BENCH_BITS, false); + do b.iter { + let mut sum = 0; + for bitv.iter().advance |pres| { + sum += pres as uint; + } + } + } + + #[bench] + fn bench_bitvset_iter(b: &mut BenchHarness) { + let bitv = BitvSet::from_bitv(from_fn(BENCH_BITS, + |idx| {idx % 3 == 0})); + do b.iter { + let mut sum = 0; + for bitv.iter().advance |idx| { + sum += idx; + } + } + } } |
