From 57c3be60c3a9477b063cc0a2df4b90c8ead1dcc1 Mon Sep 17 00:00:00 2001 From: Adewumi Sunkanmi Date: Wed, 8 Jan 2025 21:38:19 +0100 Subject: [PATCH] [Feat] Benchmark with Criterion --- Cargo.toml | 8 +++++ bench/benchmark.rs | 28 ++++++++++++++++++ .../sstable_1720785462309/summary.db | Bin 918 -> 936 bytes 3 files changed, 36 insertions(+) create mode 100644 bench/benchmark.rs diff --git a/Cargo.toml b/Cargo.toml index 52cb9cf..8265b0d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -38,3 +38,11 @@ uuid = { version = "0.8", features = ["serde", "v4"] } use = "0.0.1-pre.0" [target.'cfg(target_os = "linux")'] + +[dev-dependencies] +criterion = { version = "0.5.1", features = ["html_reports"] } + +[[bench]] +name = "velarixdb" +harness = false +path = "bench/benchmark.rs" \ No newline at end of file diff --git a/bench/benchmark.rs b/bench/benchmark.rs new file mode 100644 index 0000000..52bf677 --- /dev/null +++ b/bench/benchmark.rs @@ -0,0 +1,28 @@ +use criterion::{criterion_group, criterion_main, Criterion}; +use tempfile::tempdir; +use tokio::runtime; +use velarixdb::db::DataStore; + +// Not sure if this is the best way to implement benchmark for async ops but +// for now it LGTM (logically), review is accepted! +fn insert_many(c: &mut Criterion) { + let root = tempdir().unwrap(); + let path = root.path().join("default"); + let rt = runtime::Runtime::new().unwrap(); + let mut store = { rt.block_on(async { DataStore::open("benchmark", path).await.unwrap() }) }; + c.bench_function("insert_many", |b| { + b.iter(|| { + rt.block_on(async { + for e in 1..=3000 { + let e = e.to_string(); + store.put(&e, &e).await.unwrap(); + } + }); + }); + }); +} + + + +criterion_group!(benches, insert_many); +criterion_main!(benches); diff --git a/src/tests/fixtures/data/buckets/bucket1201eb6b-8903-4557-a5bd-d87cb725f1d8/sstable_1720785462309/summary.db b/src/tests/fixtures/data/buckets/bucket1201eb6b-8903-4557-a5bd-d87cb725f1d8/sstable_1720785462309/summary.db index 941de466bed2a0d9295e1b6bf1e18b6853f0aeae..e4ec779d5e207640738729ee1375b80442d3489e 100644 GIT binary patch delta 10 RcmbQnzJh(jH0FsDga8$l1IYjY delta 7 OcmZ3%K8=0DG-dz`5(1V0