Skip to content

Commit

Permalink
AllocRingBuffer: separate size from capacity and remove power of 2 di…
Browse files Browse the repository at this point in the history
…stinction
  • Loading branch information
tertsdiepraam committed Jun 9, 2023
1 parent 3b85e63 commit 4b0613e
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 214 deletions.
23 changes: 5 additions & 18 deletions benches/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ macro_rules! generate_benches {
(non_power_two, $c: tt, $rb: tt, $ty: tt, $fn: tt, $bmfunc: tt, $($i:tt),*) => {
$(
$c.bench_function(&format!("{} {} 1M capacity not power of two {}", stringify!($rb), stringify!($bmfunc), stringify!($i)), |b| $bmfunc(b, || {
$rb::<$ty, _>::$fn($i)
$rb::<$ty>::$fn($i)
}));
)*
};
Expand All @@ -87,19 +87,6 @@ macro_rules! generate_benches {
};
}

fn benchmark_non_power_of_two<const L: usize>(b: &mut Bencher) {
b.iter(|| {
let mut rb = AllocRingBuffer::with_capacity_non_power_of_two(L);

for i in 0..1_000_000 {
rb.push(i);
black_box(());
}

rb
})
}

fn criterion_benchmark(c: &mut Criterion) {
// TODO: Improve benchmarks
// * What are representative operations
Expand All @@ -111,7 +98,7 @@ fn criterion_benchmark(c: &mut Criterion) {
c,
AllocRingBuffer,
i32,
with_capacity,
new,
benchmark_push,
16,
1024,
Expand All @@ -135,7 +122,7 @@ fn criterion_benchmark(c: &mut Criterion) {
c,
AllocRingBuffer,
i32,
with_capacity,
new,
benchmark_various,
16,
1024,
Expand All @@ -159,7 +146,7 @@ fn criterion_benchmark(c: &mut Criterion) {
c,
AllocRingBuffer,
i32,
with_capacity,
new,
benchmark_push_dequeue,
16,
1024,
Expand All @@ -183,7 +170,7 @@ fn criterion_benchmark(c: &mut Criterion) {
c,
AllocRingBuffer,
i32,
with_capacity_non_power_of_two,
new,
benchmark_various,
16,
17,
Expand Down
4 changes: 1 addition & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ mod with_alloc;
#[cfg(feature = "alloc")]
pub use with_alloc::alloc_ringbuffer::AllocRingBuffer;
#[cfg(feature = "alloc")]
pub use with_alloc::alloc_ringbuffer::{NonPowerOfTwo, PowerOfTwo, RingbufferSize};
#[cfg(feature = "alloc")]
pub use with_alloc::vecdeque::GrowableAllocRingBuffer;

mod with_const_generics;
Expand Down Expand Up @@ -1381,6 +1379,6 @@ mod tests {

test_clone!(ConstGenericRingBuffer::<_, 4>::new());
test_clone!(GrowableAllocRingBuffer::<_>::new());
test_clone!(AllocRingBuffer::<_, _>::new(4));
test_clone!(AllocRingBuffer::<_>::new(4));
}
}
Loading

0 comments on commit 4b0613e

Please sign in to comment.