File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -28,6 +28,10 @@ tempfile = "3.10.1"
2828name = " db"
2929harness = false
3030
31+ [[bench ]]
32+ name = " logging"
33+ harness = false
34+
3135[[bin ]]
3236name = " argusdb"
3337path = " src/bin/argusdb.rs"
Original file line number Diff line number Diff line change 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) ;
You can’t perform that action at this time.
0 commit comments