Skip to content

Commit

Permalink
Merge pull request #114 from tertsdiepraam/cap-is-not-size
Browse files Browse the repository at this point in the history
`AllocRingBuffer`: separate size from capacity and remove power of 2 types
  • Loading branch information
jdonszelmann authored Sep 15, 2023
2 parents 5c75226 + d5edef3 commit 13dc018
Show file tree
Hide file tree
Showing 8 changed files with 87 additions and 220 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
/target
**/*.rs.bk
Cargo.lock
benchmarks.txt

# Editors
.idea
Expand Down
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 @@ -1368,6 +1366,6 @@ mod tests {

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

1 comment on commit 13dc018

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.