use crate::{append_fixed_random_data, get_fixed_journal};
use commonware_runtime::benchmarks::{context, tokio};
use commonware_utils::NZU64;
use criterion::{criterion_group, Criterion};
use std::{
num::NonZeroU64,
time::{Duration, Instant},
};
const PARTITION: &str = "test-partition";
const ITEMS_PER_BLOB: NonZeroU64 = NZU64!(10_000);
const ITEM_SIZE: usize = 32;
fn bench_fixed_append(c: &mut Criterion) {
let runner = tokio::Runner::default();
for items_to_write in [1_000, 10_000, 100_000, 1_000_000] {
c.bench_function(
&format!(
"{}/items={} size={}",
module_path!(),
items_to_write,
ITEM_SIZE
),
|b| {
b.to_async(&runner).iter_custom(|iters| async move {
let ctx = context::get::<commonware_runtime::tokio::Context>();
let mut duration = Duration::ZERO;
for _ in 0..iters {
let mut j =
get_fixed_journal::<ITEM_SIZE>(ctx.clone(), PARTITION, ITEMS_PER_BLOB)
.await;
let start = Instant::now();
append_fixed_random_data(&mut j, items_to_write).await;
duration += start.elapsed();
j.destroy().await.unwrap();
}
duration
});
},
);
}
}
criterion_group! {
name = benches;
config = Criterion::default().sample_size(10);
targets = bench_fixed_append
}