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 941de46..e4ec779 100644 Binary files a/src/tests/fixtures/data/buckets/bucket1201eb6b-8903-4557-a5bd-d87cb725f1d8/sstable_1720785462309/summary.db and b/src/tests/fixtures/data/buckets/bucket1201eb6b-8903-4557-a5bd-d87cb725f1d8/sstable_1720785462309/summary.db differ