Merge pull request #979 from sharkdp/fix/parameterized-reference
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Use parameterized benchmarks as references
authored by David Peter · committed by GitHub · parents 027f11b, 2e6abb7 · Browse files · 12 files·+390 added−92 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
12 files+390 added−92 removed
- tests:+228 added−54 removed
- other:+162 added−38 removed
Provenance
- Commit
46e1f9f- Tree
e1602dc- Author
David Peter <sharkdp@users.noreply.github.com>- Committer
GitHub <noreply@github.com>- Parent 1
027f11b- Parent 2
2e6abb7
12 files changed+390 added−92 removed
modified:doc/hyperfine.1+6 added-2 removed
114 unmodified lines115 not every time as would happen with the \fB\-\-prepare\fR option.116 .HP117 \fB\-\-reference\fR \fICMD\fP118 .IP119-Benchmark \fICMD\fP as the reference for the relative comparison of results.120-If this option is not specified, the fastest command is used as the reference.119+Use \fICMD\fP as the reference for the relative comparison of results. Without120+parameters, benchmark \fICMD\fP as a separate reference command. If this option121+is not specified, the fastest command is used as the reference.122+With \fB\-\-parameter\-scan\fR or \fB\-\-parameter\-list\fR, select an existing123+benchmark by its exact printed name. The name must match exactly one benchmark.124 .HP125 \fB\-\-reference\-name\fR \fINAME\fP126 .IP127 Give a meaningful \fINAME\fP to the reference command.128 Requires \fB\-\-reference\fR.129+Cannot be used with parameterized benchmarks; use \fB\-\-command\-name\fR instead.130 .HP131 \fB\-p\fR, \fB\-\-prepare\fR \fICMD...\fP132 .IP133 Execute \fICMD\fP before each timing run. This is useful for clearing disk caches,274 unmodified linesmodified:src/benchmark/relative_speed.rs+53 added-11 removed
14 unmodified lines15 // Less means faster16 pub relative_ordering: Ordering,17 }18 19+impl BenchmarkResultWithRelativeSpeed<'_> {20+ pub fn reference_label(&self) -> &'static str {21+ if self.is_reference {22+ " (reference)"23+ } else {24+ match self.relative_ordering {25+ Ordering::Less => " (faster)",26+ Ordering::Equal => " (same speed)",27+ Ordering::Greater => " (slower)",28+ }29+ }30+ }31+}32+33 pub fn compare_mean_time(l: &BenchmarkResult, r: &BenchmarkResult) -> Ordering {34 l.mean_wall_clock_time()35 .partial_cmp(&r.mean_wall_clock_time())36 .unwrap_or(Ordering::Equal)13 unmodified lines50 ) -> Vec<BenchmarkResultWithRelativeSpeed<'a>> {51 let mut results: Vec<_> = results52 .iter()53 .map(|result| {40- let is_reference = result == reference;54+ // Separate benchmarks can have identical names and measurements.55+ let is_reference = std::ptr::eq(result, reference);56 let relative_ordering = compare_mean_time(result, reference);57 43- if result.mean_wall_clock_time() == Time::zero() {58+ if result.mean_wall_clock_time() == Time::zero()59+ || reference.mean_wall_clock_time() == Time::zero()60+ {61 return BenchmarkResultWithRelativeSpeed {62 result,63 relative_speed: if is_reference { 1.0 } else { f64::INFINITY },64 relative_speed_stddev: None,15 unmodified lines80 let ratio_stddev = match (81 result.measurements.stddev(),82 reference.measurements.stddev(),83 ) {67- (Some(result_stddev), Some(fastest_stddev)) => Some(84+ (Some(result_stddev), Some(reference_stddev)) => Some(85 ratio86 * ((result_stddev / result.mean_wall_clock_time())87 .powi(uom::typenum::P2::new())71- + (fastest_stddev / reference.mean_wall_clock_time())88+ + (reference_stddev / reference.mean_wall_clock_time())89 .powi(uom::typenum::P2::new()))90 .sqrt(),91 ),92 _ => None,45 unmodified lines138 139 Some(compute_relative_speeds(results, fastest, sort_order))140 }141 125-/// Same as compute_with_check, potentially resulting in relative speeds of infinity126-pub fn compute(127- results: &[BenchmarkResult],142+/// Compute relative speeds against the given reference, or the fastest result.143+pub fn compute<'a>(144+ results: &'a [BenchmarkResult],145 sort_order: SortOrder,129-) -> Vec<BenchmarkResultWithRelativeSpeed<'_>> {130- let fastest = fastest_of(results);131-132- compute_relative_speeds(results, fastest, sort_order)146+ reference: Option<&'a BenchmarkResult>,147+) -> Vec<BenchmarkResultWithRelativeSpeed<'a>> {148+ let reference = reference.unwrap_or_else(|| fastest_of(results));149+ compute_relative_speeds(results, reference, sort_order)150 }151 152 #[cfg(test)]153 fn create_result(name: &str, mean: f64) -> BenchmarkResult {54 unmodified lines208 let annotated_results = compute_with_check(&results, SortOrder::Command);209 210 assert!(annotated_results.is_none());211 }212+213+#[test]214+fn reference_identity_distinguishes_equal_results() {215+ let results = vec![create_result("same", 1.0), create_result("same", 1.0)];216+ let entries = compute_relative_speeds(&results, &results[0], SortOrder::Command);217+218+ assert!(entries[0].is_reference);219+ assert!(!entries[1].is_reference);220+}221+222+#[test]223+fn reference_ratios_handle_zero_times() {224+ let mut results = vec![create_result("reference", 2.0), create_result("zero", 0.0)];225+ for result in &mut results {226+ let measurement = result.measurements.measurements[0];227+ result.measurements.measurements.push(measurement);228+ }229+ let entries = compute_relative_speeds(&results, &results[0], SortOrder::Command);230+ assert_eq!(entries[1].relative_speed, f64::INFINITY);231+232+ let entries = compute_relative_speeds(&results, &results[1], SortOrder::Command);233+ assert_eq!(entries[0].relative_speed, f64::INFINITY);234+ assert_eq!(entries[0].relative_speed_stddev, None);235+ assert_eq!(entries[1].relative_speed, 1.0);236+}modified:src/benchmark/scheduler.rs+13 added-6 removed
52 unmodified lines53 .push(Benchmark::new(number, cmd, self.options, &*executor).run()?);54 55 // We export results after each individual benchmark, because56 // we would risk losing them if a later benchmark fails.57- self.export_manager.write_results(&self.results, true)?;57+ self.export_manager58+ .write_results(&self.results, true, self.options.reference_index)?;59 }60 61 Ok(())62 }8 unmodified lines71 }72 73 let reference = self74 .options74- .reference_command75- .as_ref()76- .map(|_| &self.results[0])75+ .reference_index76+ .map(|index| &self.results[index])77 .unwrap_or_else(|| relative_speed::fastest_of(&self.results));78 79 if let Some(annotated_results) = relative_speed::compute_with_check_from_reference(80 &self.results,48 unmodified lines129 SortOrder::Command => {130 console_writeln!(stdout, "{}", "Relative speed comparison".bold())?;131 132 for item in annotated_results {133+ let relationship = if self.options.reference_index.is_some() {134+ item.reference_label()135+ } else {136+ ""137+ };138 console_writeln!(139 stdout,135- " {}{} {}",140+ " {}{} {}{}",141 format!("{:10.2}", item.relative_speed).bold().green(),142 if item.is_reference {143 " ".into()144 } else if let Some(stddev) = item.relative_speed_stddev {1 unmodified line146 } else {147 " ".into()148 },149 item.result.command_with_unused_parameters,150+ relationship,151 )?;152 }153 }154 }13 unmodified lines168 Ok(())169 }170 171 pub fn final_export(&self) -> Result<()> {166- self.export_manager.write_results(&self.results, false)172+ self.export_manager173+ .write_results(&self.results, false, self.options.reference_index)174 }175 }176 177 #[cfg(test)]67 unmodified linesmodified:src/export/csv.rs+2 added-1 removed
16 unmodified lines17 &self,18 results: &[BenchmarkResult],19 _unit: Option<TimeUnit>,20 _sort_order: SortOrder,21+ _reference_index: Option<usize>,22 ) -> Result<Vec<u8>> {23 const CSV_UNIT: TimeUnit = TimeUnit::Second;24 const CSV_PRECISION: usize = 6;25 146 unmodified lines172 ];173 174 let actual = String::from_utf8(175 exporter175- .serialize(&results, Some(TimeUnit::Second), SortOrder::Command)176+ .serialize(&results, Some(TimeUnit::Second), SortOrder::Command, None)177 .unwrap(),178 )179 .unwrap();180 6 unmodified linesmodified:src/export/json.rs+1 added
20 unmodified lines21 &self,22 results: &[BenchmarkResult],23 _unit: Option<TimeUnit>,24 _sort_order: SortOrder,25+ _reference_index: Option<usize>,26 ) -> Result<Vec<u8>> {27 let mut output = to_vec_pretty(&HyperfineSummary { results });28 if let Ok(ref mut content) = output {29 content.push(b'\n');5 unmodified linesmodified:src/export/markup.rs+34 added-10 removed
1 use crate::benchmark::relative_speed::BenchmarkResultWithRelativeSpeed;2 use crate::benchmark::{benchmark_result::BenchmarkResult, relative_speed};3 use crate::options::SortOrder;4-use crate::quantity::{FormatQuantity, IsUnit, TimeUnit};4+use crate::quantity::{FormatQuantity, IsUnit, Time, TimeUnit, Zero};5 6 use super::Exporter;7 use anyhow::Result;8+use std::cmp::Ordering;9 10 pub enum Alignment {11 Left,12 Right,3 unmodified lines16 fn table_results(17 &self,18 entries: &[BenchmarkResultWithRelativeSpeed],19 unit: TimeUnit,20+ reference_pending: bool,21+ explicit_reference: bool,22 ) -> String {23 // prepare table header strings24 let notation = format!("[{}]", unit.short_name());25 34 unmodified lines60 "".into()61 };62 let min_str = measurement.measurements.min().format_value(unit);63 let max_str = measurement.measurements.max().format_value(unit);61- let rel_str = format!("{:.2}", entry.relative_speed);62- let rel_stddev_str = if entry.is_reference {63- "".into()64- } else if let Some(stddev) = entry.relative_speed_stddev {65- format!(" ± {stddev:.2}")64+ // The ratio of two zero times is undefined, even if they compare equal.65+ let relative_unavailable = reference_pending66+ || (explicit_reference67+ && !entry.is_reference68+ && entry.relative_ordering == Ordering::Equal69+ && measurement.mean_wall_clock_time() == Time::zero());70+ let relative = if relative_unavailable {71+ "N/A".to_string()72 } else {67- "".into()73+ let stddev = match (entry.is_reference, entry.relative_speed_stddev) {74+ (false, Some(stddev)) => format!(" ± {stddev:.2}"),75+ _ => String::new(),76+ };77+ let label = if explicit_reference {78+ entry.reference_label()79+ } else {80+ ""81+ };82+ format!("{:.2}{stddev}{label}", entry.relative_speed)83 };84 85 // prepare table row entries86 table.push_str(&self.table_row(&[87 &self.command(&cmd_str),88 &format!("{mean_str}{stddev_str}"),89 &min_str,90 &max_str,76- &format!("{rel_str}{rel_stddev_str}"),91+ &relative,92 ]))93 }94 95 // emit table footer format32 unmodified lines128 &self,129 results: &[BenchmarkResult],130 unit: Option<TimeUnit>,131 sort_order: SortOrder,132+ reference_index: Option<usize>,133 ) -> Result<Vec<u8>> {134 let unit = unit.unwrap_or_else(|| determine_unit_from_results(results));135+ // Do not report ratios against another benchmark while the selected136+ // reference is still pending in an intermediate export.137+ let reference_pending = reference_index.is_some_and(|i| i >= results.len());119- let entries = relative_speed::compute(results, sort_order);138+ let entries = relative_speed::compute(139+ results,140+ sort_order,141+ reference_index.and_then(|i| results.get(i)),142+ );143 121- let table = self.table_results(&entries, unit);144+ let table =145+ self.table_results(&entries, unit, reference_pending, reference_index.is_some());146 Ok(table.as_bytes().to_vec())147 }148 }modified:src/export/mod.rs+10 added-2 removed
49 unmodified lines50 &self,51 results: &[BenchmarkResult],52 unit: Option<TimeUnit>,53 sort_order: SortOrder,54+ reference_index: Option<usize>,55 ) -> Result<Vec<u8>>;56 }57 58 pub enum ExportTarget {71 unmodified lines130 /// is the final call after all benchmarks have been finished. In the former case,131 /// results are written to all file targets (to always have them up to date, even132 /// if a benchmark fails). In the latter case, we only print to stdout targets (in133 /// order not to clutter the output of hyperfine with intermediate results).133- pub fn write_results(&self, results: &[BenchmarkResult], intermediate: bool) -> Result<()> {134+ /// `reference_index` refers to the complete benchmark sequence, so it can135+ /// point past `results` while that benchmark is still pending.136+ pub fn write_results(137+ &self,138+ results: &[BenchmarkResult],139+ intermediate: bool,140+ reference_index: Option<usize>,141+ ) -> Result<()> {142 for e in &self.exporters {143 let content = || {144 e.exporter137- .serialize(results, self.time_unit, self.sort_order)145+ .serialize(results, self.time_unit, self.sort_order, reference_index)146 };147 148 match e.target {149 ExportTarget::File(ref filename) => {27 unmodified linesmodified:src/export/tests.rs+1 added-1 removed
12 unmodified lines13 unit: Option<TimeUnit>,14 sort_order: SortOrder,15 ) -> String {16 let exporter = E::default();17- String::from_utf8(exporter.serialize(results, unit, sort_order).unwrap()).unwrap()17+ String::from_utf8(exporter.serialize(results, unit, sort_order, None).unwrap()).unwrap()18 }19 20 /// Ensure the makrup output includes the table header and the multiple21 /// benchmark results as a table. The list of actual times is not included404 unmodified linesmodified:src/cli.rs+7 added-3 removed
103 unmodified lines104 .long("reference")105 .action(ArgAction::Set)106 .value_name("CMD")107 .help(108- "The reference command for the relative comparison of results. \109- If this is unset, results are compared with the fastest command as reference."108+ "The reference for the relative comparison of results. Without parameters, \109+ CMD is run as a separate reference command. With --parameter-scan or \110+ --parameter-list, CMD must exactly match one unique benchmark name as \111+ shown in the output. If this is unset, results are compared with the \112+ fastest command as reference."113 )114 )115 .arg(116 Arg::new("reference-name")117 .long("reference-name")118 .action(ArgAction::Set)119 .value_name("CMD")117- .help("Give a meaningful name to the reference command.")120+ .help("Give a meaningful name to the reference command. This cannot be used \121+ with parameterized benchmarks; use --command-name instead.")122 .requires("reference")123 )124 .arg(125 Arg::new("prepare")311 unmodified linesmodified:src/options.rs+35 added-2 removed
2 unmodified lines3 use std::path::PathBuf;4 use std::process::{Command, Stdio};5 use std::{cmp, env, fmt, io};6 7-use anyhow::ensure;7+use anyhow::{bail, ensure};8 use clap::ArgMatches;9 10 use crate::command::Commands;11 use crate::error::OptionsError;195 unmodified lines207 208 /// Whether or not to ignore non-zero exit codes209 pub command_failure_action: CmdFailureAction,210 211- // Command to use as a reference for relative speed comparison211+ // Standalone reference command, cleared when an existing benchmark is selected.212 pub reference_command: Option<String>,213 214 // Name of the reference command215 pub reference_name: Option<String>,216 217+ // Index of the reference in the benchmark sequence, if any.218+ pub reference_index: Option<usize>,219+220 /// Command(s) to run before each timing run221 pub preparation_command: Option<Vec<String>>,222 223 /// Command(s) to run after each timing run35 unmodified lines259 min_benchmarking_time: Time::new::<second>(3.0),260 command_failure_action: CmdFailureAction::RaiseError,261 reference_command: None,262 reference_name: None,263+ reference_index: None,264 preparation_command: None,265 conclusion_command: None,266 setup_command: None,267 cleanup_command: None,199 unmodified lines467 Ok(options)468 }469 470 pub fn validate_against_command_list(&mut self, commands: &Commands) -> Result<()> {471+ if let Some(reference) = &self.reference_command {472+ if commands473+ .iter()474+ .next()475+ .is_some_and(|command| !command.get_parameters().is_empty())476+ {477+ ensure!(478+ self.reference_name.is_none(),479+ "--reference-name cannot be used with a parameterized reference; use --command-name to name the benchmark"480+ );481+ let mut matches = commands482+ .iter()483+ .enumerate()484+ .filter(|(_, command)| command.get_name_with_unused_parameters() == *reference);485+ let Some((index, _)) = matches.next() else {486+ bail!(487+ "Reference '{reference}' does not match any parameterized benchmark. Use its full displayed benchmark name."488+ );489+ };490+ ensure!(491+ matches.next().is_none(),492+ "Reference '{reference}' matches multiple parameterized benchmarks. Use --command-name to give them unique names."493+ );494+ self.reference_index = Some(index);495+ self.reference_command = None;496+ } else {497+ self.reference_index = Some(0);498+ }499+ }500 let has_reference_command = self.reference_command.is_some();501 let num_commands = commands.num_commands(has_reference_command);502 503 if let Some(preparation_command) = &self.preparation_command {73 unmodified linesmodified:tests/execution_order_tests.rs-20 removed
382 unmodified lines383 .run();384 }385 386 #[test]387-fn reference_is_executed_first_parameter_value() {388- ExecutionOrderTest::new()389- .arg("--runs=2")390- .reference("reference")391- .arg("--parameter-list")392- .arg("number")393- .arg("1,2,3")394- .command("command {number}")395- .expect_output("reference")396- .expect_output("reference")397- .expect_output("command 1")398- .expect_output("command 1")399- .expect_output("command 2")400- .expect_output("command 2")401- .expect_output("command 3")402- .expect_output("command 3")403- .run();404-}405-406-#[test]387 fn reference_is_executed_separately_from_commands() {388 ExecutionOrderTest::new()389 .arg("--runs=1")390 .reference("command 1")153 unmodified linesmodified:tests/integration_tests.rs+228 added-34 removed
704 unmodified lines705 ");706 }707 708 #[test]709+fn command_sorted_comparison_and_markup_identify_reference() {710+ let _settings = snapshot_settings().bind_to_scope();711+ let directory = tempfile::tempdir().unwrap();712+ let export_path = directory.path().join("results.md");713+ let output = hyperfine_debug()714+ .args([715+ "--style=basic",716+ "--runs=1",717+ "--sort=command",718+ "--reference",719+ "sleep 2",720+ "--reference-name",721+ "baseline",722+ "--export-markdown",723+ ])724+ .arg(&export_path)725+ .args(["sleep 1", "sleep 2", "sleep 3"])726+ .output()727+ .unwrap();728+ assert!(output.status.success(), "{:?}", output);729+ let stdout = String::from_utf8(output.stdout).unwrap();730+ let comparison = stdout.split_once("Relative speed comparison\n").unwrap().1;731+ insta::assert_snapshot!(comparison, @r"732+ 1.00 baseline (reference)733+ 2.00 sleep 1 (faster)734+ 1.00 sleep 2 (same speed)735+ 1.50 sleep 3 (slower)736+ ");737+ let markdown = std::fs::read_to_string(export_path).unwrap();738+ insta::assert_snapshot!(markdown, @r"739+ | Command | Mean [s] | Min [s] | Max [s] | Relative |740+ |:---|---:|---:|---:|---:|741+ | `baseline` | 2.000 | 2.000 | 2.000 | 1.00 (reference) |742+ | `sleep 1` | 1.000 | 1.000 | 1.000 | 2.00 (faster) |743+ | `sleep 2` | 2.000 | 2.000 | 2.000 | 1.00 (same speed) |744+ | `sleep 3` | 3.000 | 3.000 | 3.000 | 1.50 (slower) |745+ ");746+747+ // Equal zero times have no meaningful relative factor.748+ let output = hyperfine_debug()749+ .args([750+ "--style=none",751+ "--runs=1",752+ "--export-markdown=-",753+ "--reference",754+ "sleep 0",755+ "--reference-name",756+ "baseline",757+ "sleep 0",758+ ])759+ .output()760+ .unwrap();761+ assert!(output.status.success(), "{:?}", output);762+ let markdown = String::from_utf8(output.stdout).unwrap();763+ let row = markdown764+ .lines()765+ .find(|line| line.contains("sleep 0"))766+ .unwrap();767+ assert!(row.ends_with("| N/A |"), "{}", row);768+}769+770+#[test]771 fn shows_reference_name() {772 let _settings = snapshot_settings().bind_to_scope();773 assert_cmd_snapshot!(hyperfine_debug()774 .arg("--style=basic")81 unmodified lines856 ));857 }858 }859 860+#[cfg(unix)]861 #[test]799-fn performs_reference_and_all_benchmarks_in_parameter_scan() {862+fn selects_reference_with_parameterized_prepare() {863+ let directory = tempfile::tempdir().unwrap();864+ let csv_path = directory.path().join("results.csv");865+ let json_path = directory.path().join("results.json");866+ let output = hyperfine_raw_command()867+ .args([868+ "--style=basic",869+ "--shell=none",870+ "--runs=1",871+ "-L",872+ "delay",873+ "0.2,0.4,0.6",874+ "--prepare",875+ "sleep {delay}",876+ "--reference",877+ "echo a (delay = 0.4)",878+ "--export-csv",879+ ])880+ .arg(&csv_path)881+ .arg("--export-json")882+ .arg(&json_path)883+ .arg("echo a")884+ .output()885+ .unwrap();886+ assert!(output.status.success(), "{:?}", output);887+ let stdout = String::from_utf8(output.stdout).unwrap();888+ assert_eq!(stdout.matches("Benchmark ").count(), 3);889+ for (number, delay) in ["0.2", "0.4", "0.6"].iter().enumerate() {890+ assert!(891+ stdout.contains(&format!(892+ "Benchmark {}: echo a (delay = {})",893+ number + 1,894+ delay895+ )),896+ "{}",897+ stdout898+ );899+ }900+ assert!(stdout.contains("echo a (delay = 0.4) ran"), "{}", stdout);901+902+ let mut csv = csv::Reader::from_path(csv_path).unwrap();903+ assert!(csv904+ .headers()905+ .unwrap()906+ .iter()907+ .any(|header| header == "parameter_delay"));908+ assert_eq!(909+ csv.records().collect::<Result<Vec<_>, _>>().unwrap().len(),910+ 3911+ );912+ let json: serde_json::Value =913+ serde_json::from_slice(&std::fs::read(json_path).unwrap()).unwrap();914+ let results = json["results"].as_array().unwrap();915+ assert_eq!(results.len(), 3);916+ assert_eq!(917+ results918+ .iter()919+ .map(|result| result["parameters"]["delay"].as_str().unwrap())920+ .collect::<Vec<_>>(),921+ ["0.2", "0.4", "0.6"]922+ );923+}924+925+#[test]926+fn rejects_unmatched_reference_before_export_or_setup() {927+ let directory = tempfile::tempdir().unwrap();928+ let export_path = directory.path().join("results.csv");929+ let marker_path = directory.path().join("setup-ran");930+ std::fs::write(&export_path, "previous contents").unwrap();931+932+ hyperfine()933+ .args(["--reference", "sleep 1", "-P", "secs", "2", "3", "--setup"])934+ .arg(format!("echo touched > \"{}\"", marker_path.display()))935+ .arg("--export-csv")936+ .arg(&export_path)937+ .arg("sleep {secs}")938+ .assert()939+ .failure()940+ .stdout(predicate::str::is_empty())941+ .stderr(predicate::str::contains(942+ "does not match any parameterized benchmark",943+ ));944+ assert_eq!(945+ std::fs::read_to_string(export_path).unwrap(),946+ "previous contents"947+ );948+ assert!(!marker_path.exists());949+}950+951+#[test]952+fn rejects_ambiguous_parameterized_reference() {953+ hyperfine_debug()954+ .args([955+ "-L",956+ "x",957+ "1,2",958+ "--command-name",959+ "case",960+ "--reference",961+ "case",962+ "sleep {x}",963+ ])964+ .assert()965+ .failure()966+ .stderr(predicate::str::contains(967+ "matches multiple parameterized benchmarks",968+ ));969+}970+971+#[cfg(unix)]972+#[test]973+fn intermediate_markdown_waits_for_selected_reference() {974+ let directory = tempfile::tempdir().unwrap();975+ let export_path = directory.path().join("results.md");976+ hyperfine()977+ .args([978+ "--style=none",979+ "--shell=none",980+ "--runs=1",981+ "-L",982+ "delay",983+ "0.01,0.02,0.03",984+ "--reference",985+ "sleep 0.02",986+ "--prepare",987+ "true",988+ "--prepare",989+ "false",990+ "--prepare",991+ "true",992+ "--export-markdown",993+ ])994+ .arg(&export_path)995+ .arg("sleep {delay}")996+ .assert()997+ .failure();998+ let markdown = std::fs::read_to_string(export_path).unwrap();999+ let row = markdown1000+ .lines()1001+ .find(|line| line.contains("sleep 0.01"))1002+ .unwrap();1003+ assert!(row.ends_with("| N/A |"), "{}", row);1004+}1005+1006+#[test]1007+fn markdown_export_uses_selected_parameterized_reference() {1008 let _settings = snapshot_settings().bind_to_scope();1009 assert_cmd_snapshot!(hyperfine_debug()802- .arg("--style=basic")803- .arg("--reference=sleep 25")804- .arg("--parameter-scan")805- .arg("time")806- .arg("30")807- .arg("45")808- .arg("--parameter-step-size")809- .arg("5")810- .arg("sleep {time}"), @r"1010+ .args([1011+ "--style=none",1012+ "--runs=1",1013+ "--export-markdown=-",1014+ "-P",1015+ "x",1016+ "1",1017+ "3",1018+ "--command-name",1019+ "case-{x}",1020+ "--reference",1021+ "case-2",1022+ "sleep {x}",1023+ ]), @r"1024 success: true1025 exit_code: 01026 ----- stdout -----814- Benchmark 1: sleep 25815- Time (mean ± σ): 25.000 s ± 0.000 s [User: 0.000 s, System: 0.000 s]816- Range (min … max): 25.000 s … 25.000 s 10 runs1027 818- Benchmark 2: sleep 30819- Time (mean ± σ): 30.000 s ± 0.000 s [User: 0.000 s, System: 0.000 s]820- Range (min … max): 30.000 s … 30.000 s 10 runs1028+ | Command | Mean [s] | Min [s] | Max [s] | Relative |1029+ |:---|---:|---:|---:|---:|1030+ | `case-1` | 1.000 | 1.000 | 1.000 | 2.00 (faster) |1031+ | `case-2` | 2.000 | 2.000 | 2.000 | 1.00 (reference) |1032+ | `case-3` | 3.000 | 3.000 | 3.000 | 1.50 (slower) |1033 822- Benchmark 3: sleep 35823- Time (mean ± σ): 35.000 s ± 0.000 s [User: 0.000 s, System: 0.000 s]824- Range (min … max): 35.000 s … 35.000 s 10 runs1034 826- Benchmark 4: sleep 40827- Time (mean ± σ): 40.000 s ± 0.000 s [User: 0.000 s, System: 0.000 s]828- Range (min … max): 40.000 s … 40.000 s 10 runs829-830- Benchmark 5: sleep 45831- Time (mean ± σ): 45.000 s ± 0.000 s [User: 0.000 s, System: 0.000 s]832- Range (min … max): 45.000 s … 45.000 s 10 runs833-834- Summary835- sleep 25 ran836- 1.20 ± 0.00 times faster than sleep 30837- 1.40 ± 0.00 times faster than sleep 35838- 1.60 ± 0.00 times faster than sleep 40839- 1.80 ± 0.00 times faster than sleep 45840-1035 ----- stderr -----1036 ");1037 }1038 237 unmodified lines