Skip to content

Commit af0c541

Browse files
authored
Merge pull request #4346 from RalfJung/bench
./miri bench: sort results alphabetically
2 parents bc01240 + ff83b08 commit af0c541

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

miri-script/src/commands.rs

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::collections::HashMap;
1+
use std::collections::BTreeMap;
22
use std::ffi::{OsStr, OsString};
33
use std::fmt::Write as _;
44
use std::fs::{self, File};
@@ -489,7 +489,9 @@ impl Command {
489489
sh.read_dir(benches_dir)?
490490
.into_iter()
491491
.filter(|path| path.is_dir())
492-
.map(|path| path.into_os_string().into_string().unwrap())
492+
// Only keep the basename: that matches the usage with a manual bench list,
493+
// and it ensure the path concatenations below work as intended.
494+
.map(|path| path.file_name().unwrap().to_owned().into_string().unwrap())
493495
.collect()
494496
} else {
495497
benches.into_iter().collect()
@@ -530,14 +532,16 @@ impl Command {
530532
stddev: f64,
531533
}
532534

533-
let gather_results = || -> Result<HashMap<&str, BenchResult>> {
535+
let gather_results = || -> Result<BTreeMap<&str, BenchResult>> {
534536
let baseline_temp_dir = results_json_dir.unwrap();
535-
let mut results = HashMap::new();
537+
let mut results = BTreeMap::new();
536538
for bench in &benches {
537-
let result = File::open(path!(baseline_temp_dir / format!("{bench}.bench.json")))?;
538-
let mut result: serde_json::Value =
539-
serde_json::from_reader(BufReader::new(result))?;
540-
let result: BenchResult = serde_json::from_value(result["results"][0].take())?;
539+
let result = File::open(path!(baseline_temp_dir / format!("{bench}.bench.json")))
540+
.context("failed to read hyperfine JSON")?;
541+
let mut result: serde_json::Value = serde_json::from_reader(BufReader::new(result))
542+
.context("failed to parse hyperfine JSON")?;
543+
let result: BenchResult = serde_json::from_value(result["results"][0].take())
544+
.context("failed to interpret hyperfine JSON")?;
541545
results.insert(bench as &str, result);
542546
}
543547
Ok(results)
@@ -549,15 +553,15 @@ impl Command {
549553
serde_json::to_writer_pretty(BufWriter::new(baseline), &results)?;
550554
} else if let Some(baseline_file) = load_baseline {
551555
let new_results = gather_results()?;
552-
let baseline_results: HashMap<String, BenchResult> = {
556+
let baseline_results: BTreeMap<String, BenchResult> = {
553557
let f = File::open(baseline_file)?;
554558
serde_json::from_reader(BufReader::new(f))?
555559
};
556560
println!(
557561
"Comparison with baseline (relative speed, lower is better for the new results):"
558562
);
559-
for (bench, new_result) in new_results.iter() {
560-
let Some(baseline_result) = baseline_results.get(*bench) else { continue };
563+
for (bench, new_result) in new_results {
564+
let Some(baseline_result) = baseline_results.get(bench) else { continue };
561565

562566
// Compare results (inspired by hyperfine)
563567
let ratio = new_result.mean / baseline_result.mean;

0 commit comments

Comments
 (0)