Skip to content

Commit f159ab3

Browse files
bench_tools: save specific benchmark result
1 parent 1762d43 commit f159ab3

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

crates/bench_tools/src/runner.rs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -59,23 +59,24 @@ fn run_single_benchmark(bench: &BenchmarkConfig) {
5959
}
6060

6161
/// Collects benchmark results from criterion output and saves them to the output directory.
62-
fn save_benchmark_results(_bench: &BenchmarkConfig, output_dir: &str) {
62+
fn save_benchmark_results(bench: &BenchmarkConfig, output_dir: &str) {
6363
let criterion_base = PathBuf::from("target/criterion");
64-
let Ok(entries) = fs::read_dir(&criterion_base) else { return };
6564

66-
// Collect all estimates files.
67-
for entry in entries.flatten() {
68-
let path = entry.path();
69-
if !path.is_dir() {
70-
continue;
71-
}
65+
// Get the list of criterion benchmark names to save.
66+
// If None, use the benchmark config name.
67+
let benchmark_names: Vec<&str> = match bench.criterion_benchmark_names {
68+
Some(names) => names.to_vec(),
69+
None => vec![bench.name],
70+
};
71+
72+
// Save results for each criterion benchmark name.
73+
for bench_name in benchmark_names {
74+
let bench_path = criterion_base.join(bench_name);
75+
let estimates_path = bench_path.join("new/estimates.json");
7276

73-
// Save estimates file.
74-
let estimates_path = path.join("new/estimates.json");
7577
if let Ok(data) = fs::read_to_string(&estimates_path) {
7678
if let Ok(json) = serde_json::from_str::<serde_json::Value>(&data) {
7779
if let Ok(pretty) = serde_json::to_string_pretty(&json) {
78-
let bench_name = path.file_name().unwrap().to_string_lossy();
7980
let dest =
8081
PathBuf::from(output_dir).join(format!("{}_estimates.json", bench_name));
8182
if fs::write(&dest, pretty).is_ok() {

0 commit comments

Comments
 (0)