refactor: impl Display and Default

This commit is contained in:
2025-04-09 09:21:32 +03:00
parent 620c274e54
commit c1e568aa3f
5 changed files with 58 additions and 54 deletions

View File

@@ -1,20 +1,11 @@
use std::fmt::format;
use crate::common::{
setup::{BenchParams, TEMP_DIR, init_temp_dir, setup_entries},
utils::{BASE_DIR, run_binary_with_args},
default,
setup::{BenchParams, TEMP_DIR, init_temp_dir},
utils::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();
@@ -22,37 +13,31 @@ pub fn benchmark_basic(c: &mut Criterion) {
let params = vec![
BenchParams {
depth: 1,
max_results: 0,
verbose: false,
depth: Some(1),
..Default::default()
},
BenchParams {
depth: 5,
max_results: 0,
verbose: false,
depth: Some(5),
..default()
},
BenchParams {
depth: Some(10),
..default()
},
BenchParams {
depth: Some(10),
max_results: Some(10),
..default()
},
];
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,
);
for (idx, param) in params.iter().enumerate() {
let id = BenchmarkId::new(format!("with_param_{idx}"), &param);
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")
})
b.iter(|| run_binary_with_args(temp_dir, param).expect("Failed to run binary"))
});
}