Skip to content
Myr

Consistent display name

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 eedec07 · Browse files · 8 files+34 added−40 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

8 files+34 added−40 removed

  • other:+34 added−40 removed

8 files+34 added−40 removed

modified:src/benchmark/benchmark_result.rs+16 added-25 removed
3 unmodified lines
45use crate::benchmark::measurement::Measurements;6use crate::quantity::Time;78/// Parameter value and whether it was used in the command line template8/// Parameter value9#[derive(Debug, Default, Clone, Serialize, PartialEq)]10pub struct Parameter {11 pub value: String,12 #[serde(skip_serializing)]13 pub is_unused: bool,12}1314/// Meta data and performance metrics for a single benchmark15#[derive(Debug, Default, Clone, Serialize, PartialEq)]16pub struct BenchmarkResult {19 /// The expanded command line being benchmarked17 /// The command line being benchmarked, after parameter substitution.18 /// For example, `sleep {duration}` with `duration=1` becomes `sleep 1`,19 /// regardless of any custom name.20 pub command: String,2122 /// The display name, when it differs from the command line22 /// The custom name after parameter substitution, if it differs from `command`.23 /// For example, `--command-name="wait {duration}s"` with `duration=1`24 /// produces `Some("wait 1s")`. Without a custom name, or when the expanded25 /// name equals `command`, this is `None`.26 #[serde(skip_serializing_if = "Option::is_none")]27 pub name: Option<String>,2829 /// The custom name (or `command`), followed by parameters not used in the30 /// command template, in command-line order. For example, `sleep {duration}`31 /// with `duration=1`, `branch=main`, and the custom name `wait {duration}s`32 /// produces `wait 1s (branch = main)`. Without the custom name, this is33 /// `sleep 1 (branch = main)`. Used in summaries and table exports.34 #[serde(skip_serializing)]35 pub display_name: String,3637 /// Performance metric measurements and exit codes for each run38 #[serde(flatten)]39 pub measurements: Measurements,40
10 unmodified lines
51 /// The average wall clock time52 pub fn mean_wall_clock_time(&self) -> Time {53 self.measurements.time_wall_clock_mean()54 }4445 /// The display name of the command, possibly including a list of46 /// parameters that were not used in the command line template.47 pub fn command_with_unused_parameters(&self) -> String {48 let parameters = self49 .parameters50 .iter()51 .filter(|(_, parameter)| parameter.is_unused)52 .fold(String::new(), |output, (name, parameter)| {53 output + &format!("{name} = {value}, ", value = parameter.value)54 });55 let parameters = parameters.trim_end_matches(", ");56 let parameters = if parameters.is_empty() {57 "".into()58 } else {59 format!(" ({parameters})")60 };6162 format!("{}{}", self.get_name(), parameters)63 }55}
modified:src/benchmark/mod.rs+1 added-1 removed
480 unmodified lines
481482 Ok(BenchmarkResult {483 command,484 name,485 display_name: self.command.get_name_with_unused_parameters(),486 measurements,487 parameters: self488 .command489 .get_parameters()
2 unmodified lines
492 (493 name.to_string(),494 Parameter {495 value: value.to_string(),495 is_unused: self.command.is_parameter_unused(name),496 },497 )498 })499 .collect(),
3 unmodified lines
modified:src/benchmark/relative_speed.rs+1 added
156 unmodified lines
157 use crate::quantity::second;158159 BenchmarkResult {160 command: name.into(),161 display_name: name.into(),162 name: None,163 measurements: Measurements {164 measurements: vec![Measurement {165 time_wall_clock: Time::new::<second>(mean),
72 unmodified lines
modified:src/benchmark/scheduler.rs+3 added-7 removed
87 unmodified lines
8889 let reference = annotated_results.iter().find(|r| r.is_reference).unwrap();90 let others = annotated_results.iter().filter(|r| !r.is_reference);9192 console_writeln!(93 stdout,94 " {} ran",95 reference.result.command_with_unused_parameters().cyan()96 )?;92 console_writeln!(stdout, " {} ran", reference.result.display_name.cyan())?;9394 for item in others {95 let stddev = if let Some(stddev) = item.relative_speed_stddev {96 format!(" ± {}", format!("{:.2}", stddev).green())
20 unmodified lines
117 console_writeln!(118 stdout,119 "{} {}",120 comparator,125 &item.result.command_with_unused_parameters().magenta()121 &item.result.display_name.magenta()122 )?;123 }124 }125 SortOrder::Command => {
15 unmodified lines
141 format!(" ± {}", format!("{stddev:5.2}").green())142 } else {143 " ".into()144 },149 item.result.command_with_unused_parameters(),145 item.result.display_name,146 relationship,147 )?;148 }149 }
113 unmodified lines
modified:src/export/csv.rs+2 added-4 removed
80 unmodified lines
81 let results = vec![82 BenchmarkResult {83 command: String::from("echo command_a"),84 name: Some(String::from("command_a")),85 display_name: String::from("command_a"),86 measurements: Measurements::new(vec![87 Measurement {88 time_wall_clock: Time::new::<second>(7.0),89 time_user: Time::new::<second>(7.0),
21 unmodified lines
111 params.insert(112 "foo".into(),113 Parameter {114 value: "one".into(),114 is_unused: false,115 },116 );117 params.insert(118 "bar".into(),119 Parameter {120 value: "two".into(),121 is_unused: false,121 },122 );123 params124 },125 },126 BenchmarkResult {127 command: String::from("command_b"),128 name: None,129 display_name: String::from("command_b"),130 measurements: Measurements::new(vec![131 Measurement {132 time_wall_clock: Time::new::<second>(17.0),133 time_user: Time::new::<second>(17.0),
21 unmodified lines
155 params.insert(156 "foo".into(),157 Parameter {158 value: "one".into(),159 is_unused: false,159 },160 );161 params.insert(162 "bar".into(),163 Parameter {164 value: "seven".into(),166 is_unused: false,165 },166 );167 params168 },
16 unmodified lines
modified:src/export/markup.rs+1 added-1 removed
48 unmodified lines
4950 for entry in entries {51 let result = &entry.result;52 // prepare data row strings53 let cmd_str = result.command_with_unused_parameters().replace('|', "\\|");53 let cmd_str = result.display_name.replace('|', "\\|");54 let mean_str = result.mean_wall_clock_time().format_value(time_unit);55 let stddev_str = if let Some(stddev) = result.measurements.stddev() {56 format!(" ± {}", stddev.format_value(time_unit))57 } else {
89 unmodified lines
modified:src/export/tests.rs+8 added
27 unmodified lines
28 let results = [29 BenchmarkResult {30 command: String::from("sleep 0.1"),31 name: None,32 display_name: String::from("sleep 0.1"),33 measurements: Measurements::new(vec![34 Measurement {35 time_wall_clock: Time::new::<second>(0.09),36 time_user: Time::new::<second>(0.09),
20 unmodified lines
57 },58 BenchmarkResult {59 command: String::from("sleep 2"),60 name: None,61 display_name: String::from("sleep 2"),62 measurements: Measurements::new(vec![63 Measurement {64 time_wall_clock: Time::new::<second>(2.0),65 time_user: Time::new::<second>(2.0),
65 unmodified lines
131 let results = [132 BenchmarkResult {133 command: String::from("sleep 2"),134 name: None,135 display_name: String::from("sleep 2"),136 measurements: Measurements::new(vec![137 Measurement {138 time_wall_clock: Time::new::<second>(2.1),139 time_user: Time::new::<second>(2.1),
20 unmodified lines
160 },161 BenchmarkResult {162 command: String::from("sleep 0.1"),163 name: None,164 display_name: String::from("sleep 0.1"),165 measurements: Measurements::new(vec![166 Measurement {167 time_wall_clock: Time::new::<second>(0.1),168 time_user: Time::new::<second>(0.1),
65 unmodified lines
234 let timing_results = [235 BenchmarkResult {236 command: String::from("sleep 2"),237 name: None,238 display_name: String::from("sleep 2"),239 measurements: Measurements::new(vec![240 Measurement {241 time_wall_clock: Time::new::<second>(2.1),242 time_user: Time::new::<second>(2.1),
20 unmodified lines
263 },264 BenchmarkResult {265 command: String::from("sleep 0.1"),266 name: None,267 display_name: String::from("sleep 0.1"),268 measurements: Measurements::new(vec![269 Measurement {270 time_wall_clock: Time::new::<second>(0.1),271 time_user: Time::new::<second>(0.1),
64 unmodified lines
336 let results = [337 BenchmarkResult {338 command: String::from("sleep 2"),339 name: None,340 display_name: String::from("sleep 2"),341 measurements: Measurements::new(vec![342 Measurement {343 time_wall_clock: Time::new::<second>(2.01),344 time_user: Time::new::<second>(2.01),
20 unmodified lines
365 },366 BenchmarkResult {367 command: String::from("sleep 0.1"),368 name: None,369 display_name: String::from("sleep 0.1"),370 measurements: Measurements::new(vec![371 Measurement {372 time_wall_clock: Time::new::<second>(0.11),373 time_user: Time::new::<second>(0.11),
60 unmodified lines
modified:src/quantity/mod.rs+2 added-2 removed
128 unmodified lines
129pub fn serialize_time<S>(t: &Time, s: S) -> Result<S::Ok, S::Error>130where131 S: Serializer,132{133 let mut state = s.serialize_struct("Time", 3)?;133 let mut state = s.serialize_struct("Time", 2)?;134 state.serialize_field("value", &t.get::<second>())?;135 state.serialize_field("unit", "second")?;136 state.end()137}
1 unmodified line
139pub fn serialize_information<S>(i: &Information, s: S) -> Result<S::Ok, S::Error>140where141 S: Serializer,142{143 let mut state = s.serialize_struct("Information", 3)?;143 let mut state = s.serialize_struct("Information", 2)?;144 state.serialize_field("value", &i.get::<byte>())?;145 state.serialize_field("unit", "byte")?;146 state.end()147}
97 unmodified lines