Skip to content

Commit

Permalink
batched extend
Browse files Browse the repository at this point in the history
  • Loading branch information
jdonszelmann committed Sep 15, 2023
1 parent d5a78de commit 4e3b3ca
Show file tree
Hide file tree
Showing 2 changed files with 360 additions and 14 deletions.
46 changes: 44 additions & 2 deletions benches/bench.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#![no_coverage]
use criterion::{black_box, criterion_group, criterion_main, Bencher, Criterion};
#![cfg(not(tarpaulin_include))]

use criterion::{black_box, criterion_group, criterion_main, Bencher, Criterion, BatchSize};
use ringbuffer::{AllocRingBuffer, ConstGenericRingBuffer, RingBuffer};

fn benchmark_push<T: RingBuffer<i32>, F: Fn() -> T>(b: &mut Bencher, new: F) {
Expand Down Expand Up @@ -180,6 +181,47 @@ fn criterion_benchmark(c: &mut Criterion) {
8192,
8195
];

c.bench_function("extend too many", extend_too_many);
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);
}

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

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

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

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

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

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

fn extend_too_few(b: &mut Bencher) {
let rb = ConstGenericRingBuffer::new::<8192>();
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);
Expand Down
Loading

1 comment on commit 4e3b3ca

@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.