diff --git a/docs/development.md b/docs/development.md index a8f8ea0782..d91d4910d4 100644 --- a/docs/development.md +++ b/docs/development.md @@ -487,6 +487,8 @@ cargo run --release -p photocraft-ui-egui --example perf_scenarios -- \ That writes the row's own report and stops there: it does **not** evaluate the budget, so read `p50_ms`/`p95_ms`/`max_ms` out of the JSON yourself. Use `cargo xtask perf --bench ` when you want the verdict, the merged `results.json`/`summary.md` and the regression check. +Every `--bench` name must match a `[[bench]]` name in `perf/budgets.toml`; an unknown name +is rejected before any benchmark runs or any report or baseline is written. Read the sample count before quoting a percentile. `--reps` defaults to 7 in `--quick` and 15 otherwise, it is per bench, and some rows cap it themselves (the `#211` algorithm rows use diff --git a/xtask/src/perf.rs b/xtask/src/perf.rs index d900669984..23c05f61c7 100644 --- a/xtask/src/perf.rs +++ b/xtask/src/perf.rs @@ -869,6 +869,11 @@ pub fn run(root: &Path, rest: &[&str]) -> Result<(), String> { let o = parse_opts(rest)?; let text = std::fs::read_to_string(root.join(BUDGETS)).map_err(|e| format!("read {BUDGETS}: {e}"))?; let budgets = parse_budgets(&text)?; + for name in &o.benches { + if !budgets.bench.iter().any(|b| &b.name == name) { + return Err(format!("perf: unknown bench `{name}` (see {BUDGETS})")); + } + } let baseline_value: Option = std::fs::read_to_string(root.join(BASELINE)).ok().and_then(|t| serde_json::from_str(&t).ok()); if !o.from.is_empty() { return baseline_from_files(root, &budgets, baseline_value.as_ref(), &o); @@ -1556,6 +1561,26 @@ row = "r99" assert_eq!(counts(&evaluate(&b, &reports, None, 15.0, true)), (1, 1, 0, 1), "the row the bench lacks counts as failing"); } + #[test] + fn unknown_bench_is_rejected_before_updating_the_baseline() { + let root = std::env::temp_dir().join(format!("photocraft-perf-unknown-bench-{}", std::process::id())); + std::fs::create_dir(&root).unwrap(); + std::fs::create_dir(root.join("perf")).unwrap(); + std::fs::write(root.join(BUDGETS), "[[bench]]\nname = \"known\"\npackage = \"unused\"\nrequires = \"missing.rs\"\n").unwrap(); + let baseline = "{\"schema\":1,\"sentinel\":true}"; + std::fs::write(root.join(BASELINE), baseline).unwrap(); + let results = [ + run(&root, &["--bench", "unknown", "--reuse", "--update-baseline"]), + run(&root, &["--bench", "known", "--bench", "unknown", "--quick", "--reuse", "--update-baseline"]), + ]; + let after = std::fs::read_to_string(root.join(BASELINE)).unwrap(); + std::fs::remove_dir_all(root).unwrap(); + for result in results { + assert_eq!(result, Err(format!("perf: unknown bench `unknown` (see {BUDGETS})"))); + } + assert_eq!(after, baseline, "an unknown bench must not update the baseline"); + } + #[test] fn options() { assert!(parse_opts(&["--bogus"]).is_err());