Skip to content

Commit fc033dd

Browse files
committed
perf: Add logging benchmark
1 parent f676a12 commit fc033dd

2 files changed

Lines changed: 36 additions & 0 deletions

File tree

Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ tempfile = "3.10.1"
2828
name = "db"
2929
harness = false
3030

31+
[[bench]]
32+
name = "logging"
33+
harness = false
34+
3135
[[bin]]
3236
name = "argusdb"
3337
path = "src/bin/argusdb.rs"

benches/logging.rs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
use argusdb::log::{Logger, Operation};
2+
use criterion::{Criterion, criterion_group, criterion_main};
3+
use tempfile::tempdir;
4+
5+
fn logging_benchmark(c: &mut Criterion) {
6+
let mut group = c.benchmark_group("logging");
7+
group.sample_size(10);
8+
9+
group.bench_function("write_log_entry", |b| {
10+
b.iter_custom(|iters| {
11+
let dir = tempdir().unwrap();
12+
let log_path = dir.path().join("test.log");
13+
let mut logger = Logger::new(&log_path, 1024 * 1024).unwrap(); // 1MB rotation threshold
14+
let start = std::time::Instant::now();
15+
for _ in 0..iters {
16+
let op = Operation::Insert {
17+
id: "test_doc_id".to_string(),
18+
doc: serde_json::json!({"key": "value"}),
19+
};
20+
21+
logger.log(op).unwrap();
22+
}
23+
24+
start.elapsed()
25+
})
26+
});
27+
28+
group.finish();
29+
}
30+
31+
criterion_group!(benches, logging_benchmark);
32+
criterion_main!(benches);

0 commit comments

Comments
 (0)