refactor: benchmarks

This commit is contained in:
2025-04-01 14:29:43 +03:00
parent 385a4bf20e
commit 1a0f34c996
9 changed files with 347 additions and 141 deletions

View File

@@ -0,0 +1,60 @@
use crate::common::{
setup::{BenchParams, TEMP_DIR, init_temp_dir, setup_entries},
utils::{BASE_DIR, run_binary_with_args},
};
use criterion::{BenchmarkId, Criterion};
use std::{
path::{Path, PathBuf},
process::Command,
};
fn process_directory(path: &Path) {
let binary_path = PathBuf::from(BASE_DIR).join("target/release/project-finder");
Command::new(binary_path)
.arg(path)
.output()
.expect("failed to run binary");
}
pub fn benchmark_basic(c: &mut Criterion) {
init_temp_dir();
let temp_dir = TEMP_DIR.get().unwrap().path();
let params = vec![
BenchParams {
depth: 1,
max_results: 0,
verbose: false,
},
BenchParams {
depth: 5,
max_results: 0,
verbose: false,
},
];
let mut group = c.benchmark_group("basic_scenarios");
group.bench_function("process_directory", |b| {
b.iter(|| process_directory(temp_dir))
});
for param in params {
let id = BenchmarkId::new(
format!(
"depth{}_max{}_verbose{}",
param.depth, param.max_results, param.verbose
),
param.depth,
);
group.bench_with_input(id, &param, |b, param| {
b.iter(|| {
run_binary_with_args(temp_dir, param.depth, param.max_results, param.verbose)
.expect("Failed to run binary")
})
});
}
group.finish();
}

View File

@@ -0,0 +1,6 @@
use criterion::Criterion;
pub fn benchmark_edge_cases(c: &mut Criterion) {
let mut group = c.benchmark_group("edge_cases");
group.finish();
}

3
benches/scenarios/mod.rs Normal file
View File

@@ -0,0 +1,3 @@
pub mod basic;
pub mod edge_cases;
pub mod specific;

View File

@@ -0,0 +1,6 @@
use criterion::Criterion;
pub fn benchmark_specific_scenarios(c: &mut Criterion) {
let mut group = c.benchmark_group("specific_scenarios");
group.finish();
}