Skip to content

Commit

Permalink
[Feat] Benchmark with Criterion
Browse files Browse the repository at this point in the history
  • Loading branch information
Gifted-s committed Jan 8, 2025
1 parent 020fe62 commit 57c3be6
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
8 changes: 8 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
28 changes: 28 additions & 0 deletions bench/benchmark.rs
Original file line number Diff line number Diff line change
@@ -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);
Binary file not shown.

0 comments on commit 57c3be6

Please sign in to comment.