Skip to content

Commit 165ec9d

Browse files
Hywanbnjbvr
authored andcommitted
bench: Add a benchmark for EventCacheStore::load_all_chunks_metadata.
1 parent 6f42210 commit 165ec9d

File tree

1 file changed

+44
-24
lines changed

1 file changed

+44
-24
lines changed

benchmarks/benches/linked_chunk.rs

Lines changed: 44 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -187,11 +187,14 @@ fn reading(c: &mut Criterion) {
187187

188188
while events.peek().is_some() {
189189
let events_chunk = events.by_ref().take(80).collect::<Vec<_>>();
190+
190191
if events_chunk.is_empty() {
191192
break;
192193
}
194+
193195
lc.push_items_back(events_chunk);
194196
lc.push_gap_back(Gap { prev_token: format!("gap{num_gaps}") });
197+
195198
num_gaps += 1;
196199
}
197200

@@ -205,30 +208,47 @@ fn reading(c: &mut Criterion) {
205208
// Define the throughput.
206209
group.throughput(Throughput::Elements(num_events));
207210

208-
// Get a bencher.
209-
group.bench_function(BenchmarkId::new(store_name, num_events), |bencher| {
210-
// Bench the routine.
211-
bencher.to_async(&runtime).iter(|| async {
212-
// Load the last chunk first,
213-
let (last_chunk, chunk_id_gen) =
214-
store.load_last_chunk(linked_chunk_id).await.unwrap();
215-
216-
let mut lc =
217-
lazy_loader::from_last_chunk::<128, _, _>(last_chunk, chunk_id_gen)
218-
.expect("no error when reconstructing the linked chunk")
219-
.expect("there is a linked chunk in the store");
220-
221-
// Then load until the start of the linked chunk.
222-
let mut cur_chunk_id = lc.chunks().next().unwrap().identifier();
223-
while let Some(prev) =
224-
store.load_previous_chunk(linked_chunk_id, cur_chunk_id).await.unwrap()
225-
{
226-
cur_chunk_id = prev.identifier;
227-
lazy_loader::insert_new_first_chunk(&mut lc, prev)
228-
.expect("no error when linking the previous lazy-loaded chunk");
229-
}
230-
})
231-
});
211+
// Bench the lazy loader.
212+
group.bench_function(
213+
BenchmarkId::new(format!("lazy_loader/{store_name}"), num_events),
214+
|bencher| {
215+
// Bench the routine.
216+
bencher.to_async(&runtime).iter(|| async {
217+
// Load the last chunk first,
218+
let (last_chunk, chunk_id_gen) =
219+
store.load_last_chunk(linked_chunk_id).await.unwrap();
220+
221+
let mut lc =
222+
lazy_loader::from_last_chunk::<128, _, _>(last_chunk, chunk_id_gen)
223+
.expect("no error when reconstructing the linked chunk")
224+
.expect("there is a linked chunk in the store");
225+
226+
// Then load until the start of the linked chunk.
227+
let mut cur_chunk_id = lc.chunks().next().unwrap().identifier();
228+
while let Some(prev) =
229+
store.load_previous_chunk(linked_chunk_id, cur_chunk_id).await.unwrap()
230+
{
231+
cur_chunk_id = prev.identifier;
232+
lazy_loader::insert_new_first_chunk(&mut lc, prev)
233+
.expect("no error when linking the previous lazy-loaded chunk");
234+
}
235+
})
236+
},
237+
);
238+
239+
// Bench the metadata loader.
240+
group.bench_function(
241+
BenchmarkId::new(format!("metadata/{store_name}"), num_events),
242+
|bencher| {
243+
// Bench the routine.
244+
bencher.to_async(&runtime).iter(|| async {
245+
let _metadata = store
246+
.load_all_chunks_metadata(linked_chunk_id)
247+
.await
248+
.expect("metadata must load");
249+
})
250+
},
251+
);
232252

233253
{
234254
let _guard = runtime.enter();

0 commit comments

Comments
 (0)