From 5e633936fed1ecfda917c71ee66e9a0aa41620ac Mon Sep 17 00:00:00 2001 From: hopeyen Date: Wed, 20 Dec 2023 16:07:57 -0600 Subject: [PATCH] perf: benchmark chunk file from file storage vs object storage --- subfile-exchange/benches/new_chunk_file.rs | 27 ++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/subfile-exchange/benches/new_chunk_file.rs b/subfile-exchange/benches/new_chunk_file.rs index 3a914cf..805a5d2 100644 --- a/subfile-exchange/benches/new_chunk_file.rs +++ b/subfile-exchange/benches/new_chunk_file.rs @@ -1,16 +1,35 @@ +use criterion::async_executor::FuturesExecutor; use criterion::{black_box, criterion_group, criterion_main, Criterion}; -use subfile_exchange::{subfile::ChunkFile, test_util::CHUNK_SIZE}; -fn new_chunk_file_benchmark(c: &mut Criterion) { +use subfile_exchange::{ + subfile::{local_file_system::Store, ChunkFile}, + test_util::CHUNK_SIZE, +}; +fn new_chunk_file_benchmark_file_store(c: &mut Criterion) { // ChunkFile::new(&self.config.read_dir, file_name, self.config.chunk_size) let read_dir = black_box("../example-file"); let file_name = black_box("0017234600.dbin.zst"); let file_size = black_box(CHUNK_SIZE); - c.bench_function("new_chunk_file", |b| { + c.bench_function("new_chunk_file_benchmark_file_store", |b| { b.iter(|| ChunkFile::new(read_dir, file_name, file_size).unwrap()) }); } -criterion_group!(benches, new_chunk_file_benchmark); +fn new_chunk_file_benchmark_object_store(c: &mut Criterion) { + let store = black_box(Store::new("../example-file").unwrap()); + let file_name = black_box("0017234600.dbin.zst"); + let file_size = black_box(Some(CHUNK_SIZE as usize)); + + c.bench_function("new_chunk_file_benchmark_object_store", |b| { + b.to_async(FuturesExecutor) + .iter(|| store.chunk_file(file_name, file_size)) + }); +} + +criterion_group!( + benches, + new_chunk_file_benchmark_file_store, + new_chunk_file_benchmark_object_store +); criterion_main!(benches);