lean_ctx/core/benchmark_compare/
mod.rs1pub mod competitors;
2pub mod metrics;
3pub mod report;
4pub mod system_info;
5
6use std::path::Path;
7
8use report::CompareReport;
9
10pub fn run_compare(root: &Path, output_path: Option<&str>) -> CompareReport {
11 let metrics = metrics::measure_all(root);
12 let system = system_info::collect();
13 let competitors = competitors::all_competitors();
14
15 let report = CompareReport {
16 metrics,
17 system,
18 competitors,
19 };
20
21 if let Some(out_path) = output_path {
22 let md = report::generate_markdown(&report);
23 if let Err(e) = std::fs::write(out_path, &md) {
24 eprintln!("Failed to write {out_path}: {e}");
25 } else {
26 eprintln!("Wrote benchmark report to {out_path}");
27 }
28 }
29
30 report
31}
32
33#[cfg(test)]
34mod tests {
35 use super::*;
36
37 #[test]
38 fn run_compare_produces_valid_report() {
39 let report = run_compare(Path::new("src"), None);
40 assert!(report.metrics.project_benchmark.files_measured > 0);
41 assert!(!report.competitors.is_empty());
42 assert!(!report.system.lean_ctx_version.is_empty());
43 }
44
45 #[test]
46 fn run_compare_writes_output_file() {
47 let dir = tempfile::tempdir().unwrap();
48 let out_path = dir.path().join("test_benchmarks.md");
49 let out_str = out_path.to_string_lossy().to_string();
50
51 let report = run_compare(Path::new("src"), Some(&out_str));
52 assert!(out_path.exists());
53
54 let content = std::fs::read_to_string(&out_path).unwrap();
55 assert!(content.contains("Head-to-Head"));
56 assert!(report.metrics.project_benchmark.files_measured > 0);
57 }
58}