Remove command_with_unused_parameters field
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by David Peter · committed by David Peter · parent ae0035a · Browse files · 7 files·+38 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
7 files+38 added−92 removed
- other:+38 added−92 removed
Provenance
- Commit
af4422d- Tree
a2a620c- Author
David Peter <sharkdp@users.noreply.github.com>- Committer
David Peter <mail@david-peter.de>- Parent
ae0035a
7 files changed+38 added−92 removed
modified:src/benchmark/benchmark_result.rs+29 added-71 removed
24 unmodified lines25 /// Exit codes of the process26 pub exit_code: Option<i32>,27 }28 29-use crate::benchmark::measurement::Measurements;30-use crate::quantity::{byte, second, Time};31-use crate::util::exit_code::extract_exit_code;29+#[derive(Debug, Default, Clone, Serialize, PartialEq)]30+pub struct Parameter {31+ pub value: String,32+ pub is_unused: bool,33+}34 33-/// Parameter value and whether it was used in the command line template35+/// Set of values that will be exported.36+// NOTE: `serde` is used for JSON serialization, but not for CSV serialization due to the37+// `parameters` map. Update `src/hyperfine/export/csv.rs` with new fields, as appropriate.38 #[derive(Debug, Default, Clone, Serialize, PartialEq)]39 #[serde(transparent)]40 pub struct Parameter {41 pub value: String,6 unmodified lines48 pub struct BenchmarkResult {49 /// The full command line of the program that is being benchmarked50 pub command: String,51 48- /// The full command line, including parameters not used in the command template.49- pub command_with_unused_parameters: String,50-52 /// All run time measurements53 pub runs: Vec<BenchmarkRun>,54 55 /// Parameter values for this benchmark56+ #[serde(skip_serializing_if = "BTreeMap::is_empty")]57 pub parameters: BTreeMap<String, Parameter>,58 }59 60 impl BenchmarkResult {59- /// The average wall clock time60- pub fn mean_wall_clock_time(&self) -> Time {61- self.measurements.time_wall_clock_mean()62- }63-}64-65-// Preserve the existing export format while storing typed measurements internally.66-impl Serialize for BenchmarkResult {67- fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>68- where69- S: Serializer,70- {71- let mut state = serializer.serialize_struct(72- "BenchmarkResult",73- if self.parameters.is_empty() { 11 } else { 12 },74- )?;75- state.serialize_field("command", &self.command)?;76- state.serialize_field("mean", &self.mean_wall_clock_time().get::<second>())?;77- state.serialize_field(78- "stddev",79- &self.measurements.stddev().map(|time| time.get::<second>()),80- )?;81- state.serialize_field("median", &self.measurements.median().get::<second>())?;82- state.serialize_field("user", &self.measurements.time_user_mean().get::<second>())?;83- state.serialize_field(84- "system",85- &self.measurements.time_system_mean().get::<second>(),86- )?;87- state.serialize_field("min", &self.measurements.min().get::<second>())?;88- state.serialize_field("max", &self.measurements.max().get::<second>())?;89- state.serialize_field(90- "times",91- &self92- .measurements93- .wall_clock_times()94- .map(|time| time.get::<second>())95- .collect::<Vec<_>>(),96- )?;97- state.serialize_field(98- "memory_usage_byte",99- &self100- .measurements101- .measurements102- .iter()103- .map(|measurement| measurement.peak_memory_usage.get::<byte>() as u64)104- .collect::<Vec<_>>(),105- )?;106- state.serialize_field(107- "exit_codes",108- &self109- .measurements110- .measurements111- .iter()112- .map(|measurement| extract_exit_code(measurement.exit_status))113- .collect::<Vec<_>>(),114- )?;115- if !self.parameters.is_empty() {116- state.serialize_field("parameters", &self.parameters)?;117- }118- state.end()119- }120-}121-122-impl BenchmarkResult {61 fn wall_clock_times(&self) -> Vec<Second> {62 self.runs.iter().map(|run| run.wall_clock_time).collect()63 }64 47 unmodified lines112 .map(|run| run.system_time)113 .collect::<Vec<_>>(),114 )115 }116+117+ /// The full command line of the program that is being benchmarked, possibly including a list of118+ /// parameters that were not used in the command line template.119+ pub fn command_with_unused_parameters(&self) -> String {120+ let parameters = self121+ .parameters122+ .iter()123+ .filter(|(_, parameter)| parameter.is_unused)124+ .fold(String::new(), |output, (name, parameter)| {125+ output + &format!("{name} = {value}, ", value = parameter.value)126+ });127+ let parameters = parameters.trim_end_matches(", ");128+ let parameters = if parameters.is_empty() {129+ "".into()130+ } else {131+ format!(" ({parameters})")132+ };133+134+ format!("{}{}", self.command, parameters)135+ }136 }modified:src/benchmark/mod.rs+2 added-3 removed
6 unmodified lines7 use std::cmp;8 use std::io::{self, Write};9 use std::time::Instant;10 11-use crate::benchmark::benchmark_result::BenchmarkRun;11+use crate::benchmark::benchmark_result::{BenchmarkRun, Parameter};12 use crate::benchmark::executor::BenchmarkIteration;13 use crate::command::Command;14 use crate::options::{15 CmdFailureAction, CommandOutputPolicy, ExecutorKind, Options, OutputStyleOption,472 unmodified lines488 self.run_cleanup_command(self.command.get_parameters().iter().cloned(), output_policy)?;489 490 Ok(BenchmarkResult {491 command: self.command.get_name(),492- command_with_unused_parameters: self.command.get_name_with_unused_parameters(),492 runs: times_real493 .iter()494 .zip(times_user.iter())495 .zip(times_system.iter())22 unmodified lines518 (519 name.to_string(),520 Parameter {521 value: value.to_string(),523- is_unused: self.command.is_parameter_unused(name),522+ is_unused: self.command.is_parameter_unused(&name),523 },524 )525 })526 .collect(),3 unmodified linesmodified:src/benchmark/relative_speed.rs-1 removed
149 unmodified lines150 use crate::benchmark::benchmark_result::BenchmarkRun;151 152 BenchmarkResult {153 command: name.into(),154- command_with_unused_parameters: name.into(),154 runs: vec![BenchmarkRun {155 wall_clock_time: mean,156 user_time: mean,157 system_time: 0.,71 unmodified linesmodified:src/benchmark/scheduler.rs+5 added-5 removed
90 unmodified lines91 92 console_writeln!(93 stdout,94 " {} ran",95- reference.result.command_with_unused_parameters.cyan()96- )?;95+ reference.result.command_with_unused_parameters().cyan()96+ );97 98 for item in others {99 let stddev = if let Some(stddev) = item.relative_speed_stddev {100 format!(" ± {}", format!("{:.2}", stddev).green())20 unmodified lines121 console_writeln!(122 stdout,123 "{} {}",124 comparator,125- item.result.command_with_unused_parameters.magenta()126- )?;125+ &item.result.command_with_unused_parameters().magenta()126+ );127 }128 }129 SortOrder::Command => {130 console_writeln!(stdout, "{}", "Relative speed comparison".bold())?;14 unmodified lines145 format!(" ± {}", format!("{stddev:5.2}").green())146 } else {147 " ".into()148 },149- item.result.command_with_unused_parameters,149+ item.result.command_with_unused_parameters(),150 relationship,151 )?;152 }153 }81 unmodified linesmodified:src/export/csv.rs+1 added-3 removed
66 unmodified lines67 }68 }69 70 #[cfg(test)]71-use crate::benchmark::benchmark_result::BenchmarkRun;71+use crate::benchmark::benchmark_result::{BenchmarkRun, Parameter};72 73 #[test]74 fn test_csv() {75 use crate::benchmark::benchmark_result::Parameter;7 unmodified lines83 84 let results = vec![85 BenchmarkResult {86 command: String::from("command_a"),87- command_with_unused_parameters: String::from("command_a"),87 runs: vec![88 BenchmarkRun {89 wall_clock_time: 7.0,90 user_time: 7.0,36 unmodified lines127 },128 },129 BenchmarkResult {130 command: String::from("command_b"),132- command_with_unused_parameters: String::from("command_b"),131 runs: vec![132 BenchmarkRun {133 wall_clock_time: 17.0,134 user_time: 17.0,53 unmodified linesmodified:src/export/markup.rs+1 added-1 removed
49 unmodified lines50 for entry in entries {51 let measurement = &entry.result;52 // prepare data row strings53 let cmd_str = measurement54- .command_with_unused_parameters54+ .command_with_unused_parameters()55 .replace('|', "\\|");56 let mean_str = format_duration_value(measurement.mean(), Some(unit)).0;57 let stddev_str = if let Some(stddev) = measurement.stddev() {58 format!(" ± {}", format_duration_value(stddev, Some(unit)).0)90 unmodified linesmodified:src/export/tests.rs-8 removed
25 unmodified lines26 fn test_markup_export_auto_ms() {27 let results = [28 BenchmarkResult {29 command: String::from("sleep 0.1"),30- command_with_unused_parameters: String::from("sleep 0.1"),30 runs: vec![31 BenchmarkRun {32 wall_clock_time: 0.09,33 user_time: 0.09,19 unmodified lines53 parameters: BTreeMap::new(),54 },55 BenchmarkResult {56 command: String::from("sleep 2"),58- command_with_unused_parameters: String::from("sleep 2"),57 runs: vec![58 BenchmarkRun {59 wall_clock_time: 2.0,60 user_time: 2.0,64 unmodified lines125 fn test_markup_export_auto_s() {126 let results = [127 BenchmarkResult {128 command: String::from("sleep 2"),131- command_with_unused_parameters: String::from("sleep 2"),129 runs: vec![130 BenchmarkRun {131 wall_clock_time: 2.1,132 user_time: 2.1,19 unmodified lines152 parameters: BTreeMap::new(),153 },154 BenchmarkResult {155 command: String::from("sleep 0.1"),159- command_with_unused_parameters: String::from("sleep 0.1"),156 runs: vec![157 BenchmarkRun {158 wall_clock_time: 0.1,159 user_time: 0.1,64 unmodified lines224 fn test_markup_export_manual_ms() {225 let timing_results = [226 BenchmarkResult {227 command: String::from("sleep 2"),232- command_with_unused_parameters: String::from("sleep 2"),228 runs: vec![229 BenchmarkRun {230 wall_clock_time: 2.1,231 user_time: 2.1,19 unmodified lines251 parameters: BTreeMap::new(),252 },253 BenchmarkResult {254 command: String::from("sleep 0.1"),260- command_with_unused_parameters: String::from("sleep 0.1"),255 runs: vec![256 BenchmarkRun {257 wall_clock_time: 0.1,258 user_time: 0.1,63 unmodified lines322 fn test_markup_export_manual_s() {323 let results = [324 BenchmarkResult {325 command: String::from("sleep 2"),332- command_with_unused_parameters: String::from("sleep 2"),326 runs: vec![327 BenchmarkRun {328 wall_clock_time: 2.01,329 user_time: 2.01,19 unmodified lines349 parameters: BTreeMap::new(),350 },351 BenchmarkResult {352 command: String::from("sleep 0.1"),360- command_with_unused_parameters: String::from("sleep 0.1"),353 runs: vec![354 BenchmarkRun {355 wall_clock_time: 0.11,356 user_time: 0.11,60 unmodified lines