feat: optimization refactor, test suite, and dependency cleanup
Refactored the application to improve performance, maintainability, and binary size. Key Changes: - **Core Algorithm**: Switched to a parallel, single-pass tree construction algorithm for O(N) traversal. - **Architecture**: Extract core logic from `main.rs` to `lib.rs` to enable unit testing. - **Testing**: Added comprehensive unit tests and integration tests (`tests/cli.rs`) covering CLI arguments and output formats. - **Benchmarking**: Added `criterion` benchmarks for performance tracking. - **Dependencies**: - Removed `walkdir` (logic replaced by `ignore` + custom tree). - Removed `humansize` (consolidated to `byte-unit`). - Replaced `chrono` with lightweight `time` crate. - Removed unused `atty`. - **Reporting**: Optimized CSV and JSON output for correctness and zero-copy performance. - **Documentation**: Updated CHANGELOG.md and bumped version to 0.2.0.
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
use criterion::{black_box, criterion_group, criterion_main, Criterion};
|
||||
use sized::build_tree;
|
||||
use std::fs::{self, File};
|
||||
use std::io::Write;
|
||||
use tempfile::TempDir; // Ensure this is pub in lib.rs
|
||||
|
||||
fn setup_test_dir() -> TempDir {
|
||||
let temp_dir = TempDir::new().unwrap();
|
||||
let base_path = temp_dir.path();
|
||||
|
||||
// Create a moderately deep structure
|
||||
for i in 0..10 {
|
||||
let dir_path = base_path.join(format!("dir_{}", i));
|
||||
fs::create_dir(&dir_path).unwrap();
|
||||
for j in 0..10 {
|
||||
let file_path = dir_path.join(format!("file_{}.txt", j));
|
||||
let mut file = File::create(file_path).unwrap();
|
||||
writeln!(file, "Some content for file {}-{}", i, j).unwrap();
|
||||
}
|
||||
}
|
||||
temp_dir
|
||||
}
|
||||
|
||||
fn criterion_benchmark(c: &mut Criterion) {
|
||||
let temp_dir = setup_test_dir();
|
||||
let path = temp_dir.path();
|
||||
|
||||
c.bench_function("build_tree small", |b| {
|
||||
b.iter(|| build_tree(black_box(path), black_box(false)))
|
||||
});
|
||||
}
|
||||
|
||||
criterion_group!(benches, criterion_benchmark);
|
||||
criterion_main!(benches);
|
||||
Reference in New Issue
Block a user