Skip to content
Myr

Include raw commands in JSON exports when names differ

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 1b3ec92 · Browse files · 7 files+79 added−2 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+79 added−2 removed

  • tests:+55 added−0 removed
  • other:+24 added−2 removed

7 files+79 added−2 removed

modified:src/benchmark/benchmark_result.rs+5 added-1 removed
13 unmodified lines
1415/// Meta data and performance metrics for a single benchmark16#[derive(Debug, Default, Clone, Serialize, PartialEq)]17pub struct BenchmarkResult {18 /// The full command line of the program that is being benchmarked18 /// The display name of the command being benchmarked19 pub command: String,2021 /// The expanded command line, when it differs from the display name22 #[serde(skip_serializing_if = "Option::is_none")]23 pub command_raw: Option<String>,2425 /// Performance metric measurements and exit codes for each run26 #[serde(flatten)]27 pub measurements: Measurements,28
31 unmodified lines
modified:src/benchmark/mod.rs+6 added-1 removed
473 unmodified lines
474 }475476 self.run_cleanup_command(self.command.get_parameters().iter().cloned(), output_policy)?;477478 let command = self.command.get_name();479 let command_raw = self.command.get_command_line();480 let command_raw = (command_raw != command).then_some(command_raw);481482 Ok(BenchmarkResult {479 command: self.command.get_name(),483 command,484 command_raw,485 measurements,486 parameters: self487 .command488 .get_parameters()
14 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 command_raw: None,162 measurements: Measurements {163 measurements: vec![Measurement {164 time_wall_clock: Time::new::<second>(mean),165 time_user: Time::new::<second>(mean),
71 unmodified lines
modified:src/export/csv.rs+2 added
79 unmodified lines
8081 let results = vec![82 BenchmarkResult {83 command: String::from("command_a"),84 command_raw: None,85 measurements: Measurements::new(vec![86 Measurement {87 time_wall_clock: Time::new::<second>(7.0),88 time_user: Time::new::<second>(7.0),
36 unmodified lines
125 },126 },127 BenchmarkResult {128 command: String::from("command_b"),129 command_raw: None,130 measurements: Measurements::new(vec![131 Measurement {132 time_wall_clock: Time::new::<second>(17.0),133 time_user: Time::new::<second>(17.0),
53 unmodified lines
modified:src/export/json.rs+2 added
180 unmodified lines
181 ),182 ] {183 let result = BenchmarkResult {184 command: "example".into(),185 command_raw: None,186 measurements: Measurements::new(vec![Measurement {187 peak_memory_usage: memory,188 ..Measurement::default()189 }]),
59 unmodified lines
249 let results: Vec<_> = vec![("small", vec![1.0, 3.0]), ("large", vec![10.0])]250 .into_iter()251 .map(|(size, times)| BenchmarkResult {252 command: "example".into(),253 command_raw: None,254 parameters: [(255 "size".into(),256 Parameter {257 value: size.into(),
83 unmodified lines
modified:src/export/tests.rs+8 added
26 unmodified lines
27fn test_markup_export_auto_ms() {28 let results = [29 BenchmarkResult {30 command: String::from("sleep 0.1"),31 command_raw: None,32 measurements: Measurements::new(vec![33 Measurement {34 time_wall_clock: Time::new::<second>(0.09),35 time_user: Time::new::<second>(0.09),
19 unmodified lines
55 parameters: BTreeMap::new(),56 },57 BenchmarkResult {58 command: String::from("sleep 2"),59 command_raw: None,60 measurements: Measurements::new(vec![61 Measurement {62 time_wall_clock: Time::new::<second>(2.0),63 time_user: Time::new::<second>(2.0),
64 unmodified lines
128fn test_markup_export_auto_s() {129 let results = [130 BenchmarkResult {131 command: String::from("sleep 2"),132 command_raw: None,133 measurements: Measurements::new(vec![134 Measurement {135 time_wall_clock: Time::new::<second>(2.1),136 time_user: Time::new::<second>(2.1),
19 unmodified lines
156 parameters: BTreeMap::new(),157 },158 BenchmarkResult {159 command: String::from("sleep 0.1"),160 command_raw: None,161 measurements: Measurements::new(vec![162 Measurement {163 time_wall_clock: Time::new::<second>(0.1),164 time_user: Time::new::<second>(0.1),
64 unmodified lines
229fn test_markup_export_manual_ms() {230 let timing_results = [231 BenchmarkResult {232 command: String::from("sleep 2"),233 command_raw: None,234 measurements: Measurements::new(vec![235 Measurement {236 time_wall_clock: Time::new::<second>(2.1),237 time_user: Time::new::<second>(2.1),
19 unmodified lines
257 parameters: BTreeMap::new(),258 },259 BenchmarkResult {260 command: String::from("sleep 0.1"),261 command_raw: None,262 measurements: Measurements::new(vec![263 Measurement {264 time_wall_clock: Time::new::<second>(0.1),265 time_user: Time::new::<second>(0.1),
63 unmodified lines
329fn test_markup_export_manual_s() {330 let results = [331 BenchmarkResult {332 command: String::from("sleep 2"),333 command_raw: None,334 measurements: Measurements::new(vec![335 Measurement {336 time_wall_clock: Time::new::<second>(2.01),337 time_user: Time::new::<second>(2.01),
19 unmodified lines
357 parameters: BTreeMap::new(),358 },359 BenchmarkResult {360 command: String::from("sleep 0.1"),361 command_raw: None,362 measurements: Measurements::new(vec![363 Measurement {364 time_wall_clock: Time::new::<second>(0.11),365 time_user: Time::new::<second>(0.11),
60 unmodified lines
modified:tests/integration_tests.rs+55 added
41 unmodified lines
42 .success();43}4445#[test]46fn json_includes_raw_command_only_when_different() {47 for (args, expected) in [48 (vec!["sleep 0.01"], vec![("sleep 0.01", None)]),49 (50 vec!["--command-name=example", "sleep 0.01"],51 vec![("example", Some("sleep 0.01"))],52 ),53 (54 vec!["--command-name=sleep 0.01", "sleep 0.01"],55 vec![("sleep 0.01", None)],56 ),57 (58 vec![59 "-L",60 "delay",61 "0.01,0.02",62 "--command-name=delay {delay}",63 "sleep {delay}",64 ],65 vec![66 ("delay 0.01", Some("sleep 0.01")),67 ("delay 0.02", Some("sleep 0.02")),68 ],69 ),70 (71 vec![72 "-L",73 "delay",74 "0.01,0.02",75 "--command-name=sleep {delay}",76 "sleep {delay}",77 ],78 vec![("sleep 0.01", None), ("sleep 0.02", None)],79 ),80 ] {81 let output = hyperfine_debug()82 .args(["--runs=1", "--style=none", "--export-json=-"])83 .args(args)84 .output()85 .unwrap();86 assert!(output.status.success());87 let export: serde_json::Value = serde_json::from_slice(&output.stdout).unwrap();88 let results = export["results"].as_array().unwrap();89 assert_eq!(results.len(), expected.len());90 for (result, (command, command_raw)) in results.iter().zip(expected) {91 assert_eq!(result["command"], command);92 assert_eq!(93 result.get("command_raw"),94 command_raw.map(serde_json::Value::from).as_ref()95 );96 }97 }98}99100#[test]101fn json_memory_availability_matches_platform() {102 let output = hyperfine_raw_command()103 .args([104 "--runs=1",
1250 unmodified lines