Skip to content

Commit

Permalink
bench after one
Browse files Browse the repository at this point in the history
  • Loading branch information
jdonszelmann committed Sep 16, 2023
1 parent 14824ab commit 90675b6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
13 changes: 13 additions & 0 deletions benches/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ fn criterion_benchmark(c: &mut Criterion) {
c.bench_function("extend many too many", extend_many_too_many);
c.bench_function("extend exact cap", extend_exact_cap);
c.bench_function("extend too few", extend_too_few);
c.bench_function("extend after one", extend_after_one);
}

fn extend_many_too_many(b: &mut Bencher) {
Expand Down Expand Up @@ -232,5 +233,17 @@ fn extend_too_few(b: &mut Bencher) {
);
}

fn extend_after_one(b: &mut Bencher) {
let mut rb = ConstGenericRingBuffer::new::<8192>();
rb.push(0);
let input = (0..4096).collect::<Vec<_>>();

b.iter_batched(
&|| rb.clone(),
|mut r| black_box(r.extend(black_box(input.as_slice()))),
BatchSize::LargeInput,
);
}

criterion_group!(benches, criterion_benchmark);
criterion_main!(benches);
4 changes: 3 additions & 1 deletion src/with_const_generics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,7 @@ impl<T, const CAP: usize> ConstGenericRingBuffer<T, CAP> {

/// # Safety
/// ONLY USE WHEN WORKING ON A CLEARED RINGBUFFER
#[inline]
unsafe fn finish_iter<const BATCH_SIZE: usize>(&mut self, mut iter: impl Iterator<Item = T>) {
let mut index = 0;
for i in iter.by_ref() {
Expand All @@ -457,7 +458,8 @@ impl<T, const CAP: usize> Extend<T> for ConstGenericRingBuffer<T, CAP> {
/// NOTE: correctness (but not soundness) of extend depends on `size_hint` on iter being correct.
#[inline]
fn extend<A: IntoIterator<Item = T>>(&mut self, iter: A) {
const BATCH_SIZE: usize = 128;
const BATCH_SIZE: usize = 1;
// const BATCH_SIZE: usize = 1024;

let iter = iter.into_iter();

Expand Down

0 comments on commit 90675b6

Please sign in to comment.