Skip to content

Commit 6dd18b8

Browse files
committed
feat: add optional profiling for benchmarks
1 parent 6064c72 commit 6dd18b8

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

benches/db.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use argusdb::bench_utils::{save_profile, start_profiling};
12
use argusdb::db::DB;
23
use argusdb::query::{BinaryOperator, Expression, LogicalPlan, execute_plan};
34
use criterion::{BenchmarkId, Criterion, Throughput, criterion_group, criterion_main};
@@ -42,6 +43,16 @@ fn generate_query_plan(
4243
}
4344

4445
fn insertion_benchmark(c: &mut Criterion) {
46+
let profile_path = std::env::var("ARGUS_PROFILE").ok().map(|p| {
47+
if p.is_empty() {
48+
"insertion_profile.pb".to_string()
49+
} else {
50+
format!("insertion_{}", p)
51+
}
52+
});
53+
54+
let guard = start_profiling(&profile_path);
55+
4556
let mut group = c.benchmark_group("insertion");
4657
group.sample_size(10);
4758
let max_docs = 10_000;
@@ -76,9 +87,21 @@ fn insertion_benchmark(c: &mut Criterion) {
7687
}
7788

7889
group.finish();
90+
91+
save_profile(guard, &profile_path);
7992
}
8093

8194
fn query_benchmark(c: &mut Criterion) {
95+
let profile_path = std::env::var("ARGUS_PROFILE").ok().map(|p| {
96+
if p.is_empty() {
97+
"query_profile.pb".to_string()
98+
} else {
99+
format!("query_{}", p)
100+
}
101+
});
102+
103+
let guard = start_profiling(&profile_path);
104+
82105
let mut group = c.benchmark_group("query");
83106
group.sample_size(10);
84107
let num_docs = 10_000;
@@ -131,6 +154,8 @@ fn query_benchmark(c: &mut Criterion) {
131154
}
132155

133156
group.finish();
157+
158+
save_profile(guard, &profile_path);
134159
}
135160

136161
criterion_group!(benches, insertion_benchmark, query_benchmark);

benches/logging.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,19 @@
1+
use argusdb::bench_utils::{save_profile, start_profiling};
12
use argusdb::log::{Log, Logger, Operation};
23
use criterion::{Criterion, criterion_group, criterion_main};
34
use tempfile::tempdir;
45

56
fn logging_benchmark(c: &mut Criterion) {
7+
let profile_path = std::env::var("ARGUS_PROFILE").ok().map(|p| {
8+
if p.is_empty() {
9+
"logging_profile.pb".to_string()
10+
} else {
11+
format!("logging_{}", p)
12+
}
13+
});
14+
15+
let guard = start_profiling(&profile_path);
16+
617
let mut group = c.benchmark_group("logging");
718
group.sample_size(10);
819

@@ -26,6 +37,8 @@ fn logging_benchmark(c: &mut Criterion) {
2637
});
2738

2839
group.finish();
40+
41+
save_profile(guard, &profile_path);
2942
}
3043

3144
criterion_group!(benches, logging_benchmark);

0 commit comments

Comments
 (0)