Skip to content
Myr

Merge pull request #969 from sharkdp/codex/result-measurements

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

Store typed Measurements in BenchmarkResult

authored by David Peter · committed by GitHub · parents 30a2b61, b23372c · Browse files · 7 files+432 added−257 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+432 added−257 removed

  • other:+432 added−257 removed

7 files+432 added−257 removed

modified:src/benchmark/benchmark_result.rs+75 added-40 removed
1use std::collections::BTreeMap;23use serde::Serialize;3use serde::ser::SerializeStruct;4use serde::{Serialize, Serializer};56use crate::benchmark::measurement::Measurements;7use crate::quantity::{byte, second, Time};8use crate::util::exit_code::extract_exit_code;910/// Parameter value and whether it was used in the command line template11#[derive(Debug, Default, Clone, Serialize, PartialEq)]12#[serde(transparent)]13pub struct Parameter {
1 unmodified line
15 #[serde(skip)]16 pub is_unused: bool,17}1814/// Set of values that will be exported.15// NOTE: `serde` is used for JSON serialization, but not for CSV serialization due to the16// `parameters` map. Update `src/hyperfine/export/csv.rs` with new fields, as appropriate.17#[derive(Debug, Default, Clone, Serialize, PartialEq)]19/// Meta data and performance metrics for a single benchmark20#[derive(Debug, Default, Clone, PartialEq)]21pub struct BenchmarkResult {22 /// The full command line of the program that is being benchmarked23 pub command: String,2422 /// The full command line of the program that is being benchmarked, possibly including a list of23 /// parameters that were not used in the command line template.24 #[serde(skip_serializing)]25 /// The full command line, including parameters not used in the command template.26 pub command_with_unused_parameters: String,2727 /// The average run time28 pub mean: f64,28 /// Performance measurements and exit statuses for each run29 pub measurements: Measurements,3030 /// The standard deviation of all run times. Not available if only one run has been performed31 pub stddev: Option<f64>,3233 /// The median run time34 pub median: f64,3536 /// Time spent in user mode37 pub user: f64,3839 /// Time spent in kernel mode40 pub system: f64,4142 /// Minimum of all measured times43 pub min: f64,4445 /// Maximum of all measured times46 pub max: f64,4748 /// All run time measurements49 #[serde(skip_serializing_if = "Option::is_none")]50 pub times: Option<Vec<f64>>,5152 /// Maximum memory usage of the process, in bytes53 #[serde(skip_serializing_if = "Option::is_none")]54 pub memory_usage_byte: Option<Vec<u64>>,5556 /// Exit codes of all command invocations57 pub exit_codes: Vec<Option<i32>>,5831 /// Parameter values for this benchmark60 #[serde(skip_serializing_if = "BTreeMap::is_empty")]32 pub parameters: BTreeMap<String, Parameter>,33}3435impl BenchmarkResult {36 /// The average wall clock time37 pub fn mean_wall_clock_time(&self) -> Time {38 self.measurements.time_wall_clock_mean()39 }40}4142// Preserve the existing export format while storing typed measurements internally.43impl Serialize for BenchmarkResult {44 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>45 where46 S: Serializer,47 {48 let mut state = serializer.serialize_struct(49 "BenchmarkResult",50 if self.parameters.is_empty() { 11 } else { 12 },51 )?;52 state.serialize_field("command", &self.command)?;53 state.serialize_field("mean", &self.mean_wall_clock_time().get::<second>())?;54 state.serialize_field(55 "stddev",56 &self.measurements.stddev().map(|time| time.get::<second>()),57 )?;58 state.serialize_field("median", &self.measurements.median().get::<second>())?;59 state.serialize_field("user", &self.measurements.time_user_mean().get::<second>())?;60 state.serialize_field(61 "system",62 &self.measurements.time_system_mean().get::<second>(),63 )?;64 state.serialize_field("min", &self.measurements.min().get::<second>())?;65 state.serialize_field("max", &self.measurements.max().get::<second>())?;66 state.serialize_field(67 "times",68 &self69 .measurements70 .wall_clock_times()71 .map(|time| time.get::<second>())72 .collect::<Vec<_>>(),73 )?;74 state.serialize_field(75 "memory_usage_byte",76 &self77 .measurements78 .measurements79 .iter()80 .map(|measurement| measurement.peak_memory_usage.get::<byte>() as u64)81 .collect::<Vec<_>>(),82 )?;83 state.serialize_field(84 "exit_codes",85 &self86 .measurements87 .measurements88 .iter()89 .map(|measurement| extract_exit_code(measurement.exit_status))90 .collect::<Vec<_>>(),91 )?;92 if !self.parameters.is_empty() {93 state.serialize_field("parameters", &self.parameters)?;94 }95 state.end()96 }97}
modified:src/benchmark/measurement.rs+6 added-2 removed
2 unmodified lines
3use crate::quantity::statistics::{max, mean, median, min, modified_zscores, standard_deviation};4use crate::quantity::{Information, Time};56/// Performance measurements and exit status from running a single command7#[derive(Debug, Default, Copy, Clone)]7#[derive(Debug, Default, Copy, Clone, PartialEq)]8pub struct Measurement {9 /// Wall clock time10 pub time_wall_clock: Time,11
10 unmodified lines
22 pub exit_status: ExitStatus,23}2425/// Performance measurements and exit statuses for all runs of a command.26#[derive(Debug, Default, Clone)]26#[derive(Debug, Default, Clone, PartialEq)]27pub struct Measurements {28 pub measurements: Vec<Measurement>,29}3031impl Measurements {32 pub fn new(measurements: Vec<Measurement>) -> Self {33 Self { measurements }34 }3536 pub fn len(&self) -> usize {37 self.measurements.len()38 }39
61 unmodified lines
modified:src/benchmark/mod.rs+2 added-28 removed
15 unmodified lines
16use crate::output::console_writeln;17use crate::output::progress_bar::get_progress_bar;18use crate::output::warnings::{OutlierWarningOptions, Warnings};19use crate::parameter::ParameterNameAndValue;20use crate::quantity::{byte, const_time_from_seconds, ratio, second, FormatQuantity, Time, Zero};21use crate::util::exit_code::extract_exit_code;20use crate::quantity::{const_time_from_seconds, ratio, FormatQuantity, Time, Zero};21use benchmark_result::{BenchmarkResult, Parameter};22use measurement::{Measurement, Measurements};2324use anyhow::{anyhow, Result};
325 unmodified lines
350 // Compute statistical quantities351 let t_num = measurements.len();352 let t_mean = measurements.time_wall_clock_mean();353 let t_stddev = measurements.stddev();355 let t_median = measurements.median();354 let t_min = measurements.min();355 let t_max = measurements.max();356357 let user_mean = measurements.time_user_mean();
104 unmodified lines
462463 Ok(BenchmarkResult {464 command: self.command.get_name(),465 command_with_unused_parameters: self.command.get_name_with_unused_parameters(),468 mean: t_mean.get::<second>(),469 stddev: t_stddev.map(|t| t.get::<second>()),470 median: t_median.get::<second>(),471 user: user_mean.get::<second>(),472 system: system_mean.get::<second>(),473 min: t_min.get::<second>(),474 max: t_max.get::<second>(),475 times: Some(476 measurements466 measurements,477 .wall_clock_times()478 .map(|t| t.get::<second>())479 .collect(),480 ),481 memory_usage_byte: Some(482 measurements483 .measurements484 .iter()485 .map(|m| m.peak_memory_usage.get::<byte>() as u64)486 .collect(),487 ),488 exit_codes: measurements489 .measurements490 .iter()491 .map(|m| extract_exit_code(m.exit_status))492 .collect(),467 parameters: self468 .command469 .get_parameters()470 .iter()
13 unmodified lines
modified:src/benchmark/relative_speed.rs+41 added-19 removed
1use std::cmp::Ordering;23use super::benchmark_result::BenchmarkResult;4use crate::options::SortOrder;5use crate::quantity::second;67#[derive(Debug)]8pub struct BenchmarkResultWithRelativeSpeed<'a> {9 pub result: &'a BenchmarkResult,
4 unmodified lines
14 pub relative_ordering: Ordering,15}1617pub fn compare_mean_time(l: &BenchmarkResult, r: &BenchmarkResult) -> Ordering {17 l.mean.partial_cmp(&r.mean).unwrap_or(Ordering::Equal)18 l.mean_wall_clock_time()19 .get::<second>()20 .partial_cmp(&r.mean_wall_clock_time().get::<second>())21 .unwrap_or(Ordering::Equal)22}2324pub fn fastest_of(results: &[BenchmarkResult]) -> &BenchmarkResult {25 results
12 unmodified lines
38 .map(|result| {39 let is_reference = result == reference;40 let relative_ordering = compare_mean_time(result, reference);4138 if result.mean == 0.0 {42 if result.mean_wall_clock_time().get::<second>() == 0.0 {43 return BenchmarkResultWithRelativeSpeed {44 result,45 relative_speed: if is_reference { 1.0 } else { f64::INFINITY },46 relative_speed_stddev: None,
2 unmodified lines
49 };50 }5152 let ratio = match relative_ordering {49 Ordering::Less => reference.mean / result.mean,53 Ordering::Less => {54 reference.mean_wall_clock_time().get::<second>()55 / result.mean_wall_clock_time().get::<second>()56 }57 Ordering::Equal => 1.0,51 Ordering::Greater => result.mean / reference.mean,58 Ordering::Greater => {59 result.mean_wall_clock_time().get::<second>()60 / reference.mean_wall_clock_time().get::<second>()61 }62 };6364 // https://en.wikipedia.org/wiki/Propagation_of_uncertainty#Example_formulas65 // Covariance assumed to be 0, i.e. variables are assumed to be independent56 let ratio_stddev = match (result.stddev, reference.stddev) {66 let ratio_stddev = match (67 result68 .measurements69 .stddev()70 .map(|time| time.get::<second>()),71 reference72 .measurements73 .stddev()74 .map(|time| time.get::<second>()),75 ) {76 (Some(result_stddev), Some(fastest_stddev)) => Some(77 ratio59 * ((result_stddev / result.mean).powi(2)60 + (fastest_stddev / reference.mean).powi(2))78 * ((result_stddev / result.mean_wall_clock_time().get::<second>()).powi(2)79 + (fastest_stddev / reference.mean_wall_clock_time().get::<second>())80 .powi(2))81 .sqrt(),82 ),83 _ => None,84 };
22 unmodified lines
107 results: &'a [BenchmarkResult],108 reference: &'a BenchmarkResult,109 sort_order: SortOrder,110) -> Option<Vec<BenchmarkResultWithRelativeSpeed<'a>>> {91 if fastest_of(results).mean == 0.0 || reference.mean == 0.0 {111 if fastest_of(results).mean_wall_clock_time().get::<second>() == 0.0112 || reference.mean_wall_clock_time().get::<second>() == 0.0113 {114 return None;115 }116117 Some(compute_relative_speeds(results, reference, sort_order))
4 unmodified lines
122 sort_order: SortOrder,123) -> Option<Vec<BenchmarkResultWithRelativeSpeed<'_>>> {124 let fastest = fastest_of(results);125104 if fastest.mean == 0.0 {126 if fastest.mean_wall_clock_time().get::<second>() == 0.0 {127 return None;128 }129130 Some(compute_relative_speeds(results, fastest, sort_order))
12 unmodified lines
143#[cfg(test)]144fn create_result(name: &str, mean: f64) -> BenchmarkResult {145 use std::collections::BTreeMap;146147 use crate::benchmark::measurement::{Measurement, Measurements};148 use crate::quantity::{second, Time};149150 BenchmarkResult {151 command: name.into(),152 command_with_unused_parameters: name.into(),128 mean,129 stddev: Some(1.0),130 median: mean,131 user: mean,132 system: 0.0,133 min: mean,134 max: mean,135 times: None,136 memory_usage_byte: None,137 exit_codes: Vec::new(),153 measurements: Measurements {154 measurements: vec![Measurement {155 time_wall_clock: Time::new::<second>(mean),156 time_user: Time::new::<second>(mean),157 ..Default::default()158 }],159 },160 parameters: BTreeMap::new(),161 }162}163
39 unmodified lines
modified:src/export/csv.rs+64 added-30 removed
3 unmodified lines
45use super::Exporter;6use crate::benchmark::benchmark_result::BenchmarkResult;7use crate::options::SortOrder;8use crate::quantity::TimeUnit;8use crate::quantity::{second, TimeUnit};910use anyhow::Result;1112#[derive(Default)]
28 unmodified lines
4142 for res in results {43 let mut fields = vec![Cow::Borrowed(res.command.as_bytes())];44 for f in &[45 res.mean,46 res.stddev.unwrap_or(0.0),47 res.median,48 res.user,49 res.system,50 res.min,51 res.max,45 res.mean_wall_clock_time().get::<second>(),46 res.measurements47 .stddev()48 .unwrap_or_default()49 .get::<second>(),50 res.measurements.median().get::<second>(),51 res.measurements.time_user_mean().get::<second>(),52 res.measurements.time_system_mean().get::<second>(),53 res.measurements.min().get::<second>(),54 res.measurements.max().get::<second>(),55 ] {56 fields.push(Cow::Owned(format!("{f:.CSV_PRECISION$}").into_bytes()))57 }58 for v in res.parameters.values() {
8 unmodified lines
6768#[test]69fn test_csv() {70 use crate::benchmark::benchmark_result::Parameter;71 use crate::benchmark::measurement::{Measurement, Measurements};72 use crate::quantity::{byte, second, Information, Time, Zero};7374 use std::collections::BTreeMap;75 use std::process::ExitStatus;7677 let exporter = CsvExporter::default();7879 let results = vec![80 BenchmarkResult {81 command: String::from("command_a"),82 command_with_unused_parameters: String::from("command_a"),75 mean: 1.0,76 stddev: Some(2.0),77 median: 1.0,78 user: 3.0,79 system: 4.0,80 min: 5.0,81 max: 6.0,82 times: Some(vec![7.0, 8.0, 9.0]),83 memory_usage_byte: None,84 exit_codes: vec![Some(0), Some(0), Some(0)],83 measurements: Measurements::new(vec![84 Measurement {85 time_wall_clock: Time::new::<second>(7.0),86 time_user: Time::new::<second>(7.0),87 time_system: Time::zero(),88 peak_memory_usage: Information::new::<byte>(1024.),89 exit_status: ExitStatus::default(),90 },91 Measurement {92 time_wall_clock: Time::new::<second>(8.0),93 time_user: Time::new::<second>(8.0),94 time_system: Time::zero(),95 peak_memory_usage: Information::new::<byte>(1024.),96 exit_status: ExitStatus::default(),97 },98 Measurement {99 time_wall_clock: Time::new::<second>(12.0),100 time_user: Time::new::<second>(12.0),101 time_system: Time::zero(),102 peak_memory_usage: Information::new::<byte>(1024.),103 exit_status: ExitStatus::default(),104 },105 ]),106 parameters: {107 let mut params = BTreeMap::new();108 params.insert(109 "foo".into(),
14 unmodified lines
124 },125 BenchmarkResult {126 command: String::from("command_b"),127 command_with_unused_parameters: String::from("command_b"),107 mean: 11.0,108 stddev: Some(12.0),109 median: 11.0,110 user: 13.0,111 system: 14.0,112 min: 15.0,113 max: 16.5,114 times: Some(vec![17.0, 18.0, 19.0]),115 memory_usage_byte: None,116 exit_codes: vec![Some(0), Some(0), Some(0)],128 measurements: Measurements::new(vec![129 Measurement {130 time_wall_clock: Time::new::<second>(17.0),131 time_user: Time::new::<second>(17.0),132 time_system: Time::zero(),133 peak_memory_usage: Information::new::<byte>(1024.),134 exit_status: ExitStatus::default(),135 },136 Measurement {137 time_wall_clock: Time::new::<second>(18.0),138 time_user: Time::new::<second>(18.0),139 time_system: Time::zero(),140 peak_memory_usage: Information::new::<byte>(1024.),141 exit_status: ExitStatus::default(),142 },143 Measurement {144 time_wall_clock: Time::new::<second>(19.0),145 time_user: Time::new::<second>(19.0),146 time_system: Time::zero(),147 peak_memory_usage: Information::new::<byte>(1024.),148 exit_status: ExitStatus::default(),149 },150 ]),151 parameters: {152 let mut params = BTreeMap::new();153 params.insert(154 "foo".into(),
22 unmodified lines
177 .unwrap();178179 insta::assert_snapshot!(actual, @r#"180 command,mean,stddev,median,user,system,min,max,parameter_bar,parameter_foo147 command_a,1.000000,2.000000,1.000000,3.000000,4.000000,5.000000,6.000000,two,one148 command_b,11.000000,12.000000,11.000000,13.000000,14.000000,15.000000,16.500000,seven,one181 command_a,9.000000,2.645751,8.000000,9.000000,0.000000,7.000000,12.000000,two,one182 command_b,18.000000,1.000000,18.000000,18.000000,0.000000,17.000000,19.000000,seven,one183 "#);184}
modified:src/export/markup.rs+7 added-7 removed
1use crate::benchmark::relative_speed::BenchmarkResultWithRelativeSpeed;2use crate::benchmark::{benchmark_result::BenchmarkResult, relative_speed};3use crate::options::SortOrder;4use crate::quantity::{second, FormatQuantity, IsUnit, Time, TimeUnit};4use crate::quantity::{FormatQuantity, IsUnit, TimeUnit};56use super::Exporter;7use anyhow::Result;8
40 unmodified lines
49 // prepare data row strings50 let cmd_str = measurement51 .command_with_unused_parameters52 .replace('|', "\\|");53 let mean_str = Time::new::<second>(measurement.mean).format_value(unit);54 let stddev_str = if let Some(stddev) = measurement.stddev {55 format!(" ± {}", Time::new::<second>(stddev).format_value(unit))53 let mean_str = measurement.mean_wall_clock_time().format_value(unit);54 let stddev_str = if let Some(stddev) = measurement.measurements.stddev() {55 format!(" ± {}", stddev.format_value(unit))56 } else {57 "".into()58 };59 let min_str = Time::new::<second>(measurement.min).format_value(unit);60 let max_str = Time::new::<second>(measurement.max).format_value(unit);59 let min_str = measurement.measurements.min().format_value(unit);60 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 {
35 unmodified lines
100101fn determine_unit_from_results(results: &[BenchmarkResult]) -> TimeUnit {102 if let Some(first_result) = results.first() {103 // Use the first BenchmarkResult entry to determine the unit for all entries.104 Time::new::<second>(first_result.mean).suitable_unit()104 first_result.mean_wall_clock_time().suitable_unit()105 } else {106 // Default to `Second`.107 TimeUnit::Second108 }
16 unmodified lines
modified:src/export/tests.rs+237 added-131 removed
1use super::Exporter;2use crate::benchmark::benchmark_result::BenchmarkResult;3use crate::benchmark::measurement::{Measurement, Measurements};4use crate::export::asciidoc::AsciidocExporter;5use crate::export::orgmode::OrgmodeExporter;5use crate::quantity::TimeUnit;6use crate::quantity::{byte, second, Information, Time, TimeUnit, Zero};7use crate::{export::markdown::MarkdownExporter, options::SortOrder};8use std::collections::BTreeMap;9use std::process::ExitStatus;1011fn get_output<E: Exporter + Default>(12 results: &[BenchmarkResult],13 unit: Option<TimeUnit>,
14 unmodified lines
28 let results = [29 BenchmarkResult {30 command: String::from("sleep 0.1"),31 command_with_unused_parameters: String::from("sleep 0.1"),30 mean: 0.1057,31 stddev: Some(0.0016),32 median: 0.1057,33 user: 0.0009,34 system: 0.0011,35 min: 0.1023,36 max: 0.1080,37 times: Some(vec![0.1, 0.1, 0.1]),38 memory_usage_byte: None,39 exit_codes: vec![Some(0), Some(0), Some(0)],32 measurements: Measurements::new(vec![33 Measurement {34 time_wall_clock: Time::new::<second>(0.09),35 time_user: Time::new::<second>(0.09),36 time_system: Time::zero(),37 peak_memory_usage: Information::new::<byte>(1024.),38 exit_status: ExitStatus::default(),39 },40 Measurement {41 time_wall_clock: Time::new::<second>(0.10),42 time_user: Time::new::<second>(0.10),43 time_system: Time::zero(),44 peak_memory_usage: Information::new::<byte>(1024.),45 exit_status: ExitStatus::default(),46 },47 Measurement {48 time_wall_clock: Time::new::<second>(0.14),49 time_user: Time::new::<second>(0.14),50 time_system: Time::zero(),51 peak_memory_usage: Information::new::<byte>(1024.),52 exit_status: ExitStatus::default(),53 },54 ]),55 parameters: BTreeMap::new(),56 },57 BenchmarkResult {58 command: String::from("sleep 2"),59 command_with_unused_parameters: String::from("sleep 2"),45 mean: 2.0050,46 stddev: Some(0.0020),47 median: 2.0050,48 user: 0.0009,49 system: 0.0012,50 min: 2.0020,51 max: 2.0080,52 times: Some(vec![2.0, 2.0, 2.0]),53 memory_usage_byte: None,54 exit_codes: vec![Some(0), Some(0), Some(0)],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 time_system: Time::zero(),65 peak_memory_usage: Information::new::<byte>(1024.),66 exit_status: ExitStatus::default(),67 },68 Measurement {69 time_wall_clock: Time::new::<second>(3.0),70 time_user: Time::new::<second>(3.0),71 time_system: Time::zero(),72 peak_memory_usage: Information::new::<byte>(1024.),73 exit_status: ExitStatus::default(),74 },75 Measurement {76 time_wall_clock: Time::new::<second>(4.0),77 time_user: Time::new::<second>(4.0),78 time_system: Time::zero(),79 peak_memory_usage: Information::new::<byte>(1024.),80 exit_status: ExitStatus::default(),81 },82 ]),83 parameters: BTreeMap::new(),84 },85 ];8687 insta::assert_snapshot!(get_output::<MarkdownExporter>(&results, None, SortOrder::Command), @r#"88 | Command | Mean [ms] | Min [ms] | Max [ms] | Relative |89 |:---|---:|---:|---:|---:|62 | `sleep 0.1` | 105.7 ± 1.6 | 102.3 | 108.0 | 1.00 |63 | `sleep 2` | 2005.0 ± 2.0 | 2002.0 | 2008.0 | 18.97 ± 0.29 |90 | `sleep 0.1` | 110.0 ± 26.5 | 90.0 | 140.0 | 1.00 |91 | `sleep 2` | 3000.0 ± 1000.0 | 2000.0 | 4000.0 | 27.27 ± 11.21 |92 "#);9394 insta::assert_snapshot!(get_output::<AsciidocExporter>(&results, None, SortOrder::Command), @r#"95 [cols="<,>,>,>,>"]
4 unmodified lines
100 | Max [ms] 101 | Relative 102103 | `sleep 0.1` 76 | 105.7 ± 1.6 77 | 102.3 78 | 108.0 104 | 110.0 ± 26.5 105 | 90.0 106 | 140.0 107 | 1.00 108109 | `sleep 2` 82 | 2005.0 ± 2.0 83 | 2002.0 84 | 2008.0 85 | 18.97 ± 0.29 110 | 3000.0 ± 1000.0 111 | 2000.0 112 | 4000.0 113 | 27.27 ± 11.21 114 |===115 "#);116117 insta::assert_snapshot!(get_output::<OrgmodeExporter>(&results, None, SortOrder::Command), @r#"118 | Command | Mean [ms] | Min [ms] | Max [ms] | Relative |119 |--+--+--+--+--|92 | =sleep 0.1= | 105.7 ± 1.6 | 102.3 | 108.0 | 1.00 |93 | =sleep 2= | 2005.0 ± 2.0 | 2002.0 | 2008.0 | 18.97 ± 0.29 |120 | =sleep 0.1= | 110.0 ± 26.5 | 90.0 | 140.0 | 1.00 |121 | =sleep 2= | 3000.0 ± 1000.0 | 2000.0 | 4000.0 | 27.27 ± 11.21 |122 "#);123}124125/// This (again) demonstrates that the first entry's units (s) are used to set
3 unmodified lines
129 let results = [130 BenchmarkResult {131 command: String::from("sleep 2"),132 command_with_unused_parameters: String::from("sleep 2"),105 mean: 2.0050,106 stddev: Some(0.0020),107 median: 2.0050,108 user: 0.0009,109 system: 0.0012,110 min: 2.0020,111 max: 2.0080,112 times: Some(vec![2.0, 2.0, 2.0]),113 memory_usage_byte: None,114 exit_codes: vec![Some(0), Some(0), Some(0)],133 measurements: Measurements::new(vec![134 Measurement {135 time_wall_clock: Time::new::<second>(2.1),136 time_user: Time::new::<second>(2.1),137 time_system: Time::zero(),138 peak_memory_usage: Information::new::<byte>(1024.),139 exit_status: ExitStatus::default(),140 },141 Measurement {142 time_wall_clock: Time::new::<second>(2.2),143 time_user: Time::new::<second>(2.2),144 time_system: Time::zero(),145 peak_memory_usage: Information::new::<byte>(1024.),146 exit_status: ExitStatus::default(),147 },148 Measurement {149 time_wall_clock: Time::new::<second>(2.3),150 time_user: Time::new::<second>(2.3),151 time_system: Time::zero(),152 peak_memory_usage: Information::new::<byte>(1024.),153 exit_status: ExitStatus::default(),154 },155 ]),156 parameters: BTreeMap::new(),157 },158 BenchmarkResult {159 command: String::from("sleep 0.1"),160 command_with_unused_parameters: String::from("sleep 0.1"),120 mean: 0.1057,121 stddev: Some(0.0016),122 median: 0.1057,123 user: 0.0009,124 system: 0.0011,125 min: 0.1023,126 max: 0.1080,127 times: Some(vec![0.1, 0.1, 0.1]),128 memory_usage_byte: None,129 exit_codes: vec![Some(0), Some(0), Some(0)],161 measurements: Measurements::new(vec![162 Measurement {163 time_wall_clock: Time::new::<second>(0.1),164 time_user: Time::new::<second>(0.1),165 time_system: Time::zero(),166 peak_memory_usage: Information::new::<byte>(1024.),167 exit_status: ExitStatus::default(),168 },169 Measurement {170 time_wall_clock: Time::new::<second>(0.2),171 time_user: Time::new::<second>(0.2),172 time_system: Time::zero(),173 peak_memory_usage: Information::new::<byte>(1024.),174 exit_status: ExitStatus::default(),175 },176 Measurement {177 time_wall_clock: Time::new::<second>(0.3),178 time_user: Time::new::<second>(0.3),179 time_system: Time::zero(),180 peak_memory_usage: Information::new::<byte>(1024.),181 exit_status: ExitStatus::default(),182 },183 ]),184 parameters: BTreeMap::new(),185 },186 ];187188 insta::assert_snapshot!(get_output::<MarkdownExporter>(&results, None, SortOrder::Command), @r#"189 | Command | Mean [s] | Min [s] | Max [s] | Relative |190 |:---|---:|---:|---:|---:|137 | `sleep 2` | 2.005 ± 0.002 | 2.002 | 2.008 | 18.97 ± 0.29 |138 | `sleep 0.1` | 0.106 ± 0.002 | 0.102 | 0.108 | 1.00 |191 | `sleep 2` | 2.200 ± 0.100 | 2.100 | 2.300 | 11.00 ± 5.52 |192 | `sleep 0.1` | 0.200 ± 0.100 | 0.100 | 0.300 | 1.00 |193 "#);194195 insta::assert_snapshot!(get_output::<AsciidocExporter>(&results, None, SortOrder::Command), @r#"196 [cols="<,>,>,>,>"]
4 unmodified lines
201 | Max [s] 202 | Relative 203204 | `sleep 2` 151 | 2.005 ± 0.002 152 | 2.002 153 | 2.008 154 | 18.97 ± 0.29 205 | 2.200 ± 0.100 206 | 2.100 207 | 2.300 208 | 11.00 ± 5.52 209210 | `sleep 0.1` 157 | 0.106 ± 0.002 158 | 0.102 159 | 0.108 211 | 0.200 ± 0.100 212 | 0.100 213 | 0.300 214 | 1.00 215 |===216 "#);217218 insta::assert_snapshot!(get_output::<OrgmodeExporter>(&results, None, SortOrder::Command), @r#"219 | Command | Mean [s] | Min [s] | Max [s] | Relative |220 |--+--+--+--+--|167 | =sleep 2= | 2.005 ± 0.002 | 2.002 | 2.008 | 18.97 ± 0.29 |168 | =sleep 0.1= | 0.106 ± 0.002 | 0.102 | 0.108 | 1.00 |221 | =sleep 2= | 2.200 ± 0.100 | 2.100 | 2.300 | 11.00 ± 5.52 |222 | =sleep 0.1= | 0.200 ± 0.100 | 0.100 | 0.300 | 1.00 |223 "#);224}225226/// This (again) demonstrates that the given time unit (ms) is used to set
3 unmodified lines
230 let timing_results = [231 BenchmarkResult {232 command: String::from("sleep 2"),233 command_with_unused_parameters: String::from("sleep 2"),180 mean: 2.0050,181 stddev: Some(0.0020),182 median: 2.0050,183 user: 0.0009,184 system: 0.0012,185 min: 2.0020,186 max: 2.0080,187 times: Some(vec![2.0, 2.0, 2.0]),188 memory_usage_byte: None,189 exit_codes: vec![Some(0), Some(0), Some(0)],234 measurements: Measurements::new(vec![235 Measurement {236 time_wall_clock: Time::new::<second>(2.1),237 time_user: Time::new::<second>(2.1),238 time_system: Time::zero(),239 peak_memory_usage: Information::new::<byte>(1024.),240 exit_status: ExitStatus::default(),241 },242 Measurement {243 time_wall_clock: Time::new::<second>(2.2),244 time_user: Time::new::<second>(2.2),245 time_system: Time::zero(),246 peak_memory_usage: Information::new::<byte>(1024.),247 exit_status: ExitStatus::default(),248 },249 Measurement {250 time_wall_clock: Time::new::<second>(2.3),251 time_user: Time::new::<second>(2.3),252 time_system: Time::zero(),253 peak_memory_usage: Information::new::<byte>(1024.),254 exit_status: ExitStatus::default(),255 },256 ]),257 parameters: BTreeMap::new(),258 },259 BenchmarkResult {260 command: String::from("sleep 0.1"),261 command_with_unused_parameters: String::from("sleep 0.1"),195 mean: 0.1057,196 stddev: Some(0.0016),197 median: 0.1057,198 user: 0.0009,199 system: 0.0011,200 min: 0.1023,201 max: 0.1080,202 times: Some(vec![0.1, 0.1, 0.1]),203 memory_usage_byte: None,204 exit_codes: vec![Some(0), Some(0), Some(0)],262 measurements: Measurements::new(vec![263 Measurement {264 time_wall_clock: Time::new::<second>(0.1),265 time_user: Time::new::<second>(0.1),266 time_system: Time::zero(),267 peak_memory_usage: Information::new::<byte>(1024.),268 exit_status: ExitStatus::default(),269 },270 Measurement {271 time_wall_clock: Time::new::<second>(0.2),272 time_user: Time::new::<second>(0.2),273 time_system: Time::zero(),274 peak_memory_usage: Information::new::<byte>(1024.),275 exit_status: ExitStatus::default(),276 },277 Measurement {278 time_wall_clock: Time::new::<second>(0.3),279 time_user: Time::new::<second>(0.3),280 time_system: Time::zero(),281 peak_memory_usage: Information::new::<byte>(1024.),282 exit_status: ExitStatus::default(),283 },284 ]),285 parameters: BTreeMap::new(),286 },287 ];288289 insta::assert_snapshot!(get_output::<MarkdownExporter>(&timing_results, Some(TimeUnit::MilliSecond), SortOrder::Command), @r#"290 | Command | Mean [ms] | Min [ms] | Max [ms] | Relative |291 |:---|---:|---:|---:|---:|212 | `sleep 2` | 2005.0 ± 2.0 | 2002.0 | 2008.0 | 18.97 ± 0.29 |213 | `sleep 0.1` | 105.7 ± 1.6 | 102.3 | 108.0 | 1.00 |292 | `sleep 2` | 2200.0 ± 100.0 | 2100.0 | 2300.0 | 11.00 ± 5.52 |293 | `sleep 0.1` | 200.0 ± 100.0 | 100.0 | 300.0 | 1.00 |294 "#);295296 insta::assert_snapshot!(get_output::<AsciidocExporter>(&timing_results, Some(TimeUnit::MilliSecond), SortOrder::Command), @r#"297 [cols="<,>,>,>,>"]
4 unmodified lines
302 | Max [ms] 303 | Relative 304305 | `sleep 2` 226 | 2005.0 ± 2.0 227 | 2002.0 228 | 2008.0 229 | 18.97 ± 0.29 306 | 2200.0 ± 100.0 307 | 2100.0 308 | 2300.0 309 | 11.00 ± 5.52 310311 | `sleep 0.1` 232 | 105.7 ± 1.6 233 | 102.3 234 | 108.0 312 | 200.0 ± 100.0 313 | 100.0 314 | 300.0 315 | 1.00 316 |===317 "#);318319 insta::assert_snapshot!(get_output::<OrgmodeExporter>(&timing_results, Some(TimeUnit::MilliSecond), SortOrder::Command), @r#"320 | Command | Mean [ms] | Min [ms] | Max [ms] | Relative |321 |--+--+--+--+--|242 | =sleep 2= | 2005.0 ± 2.0 | 2002.0 | 2008.0 | 18.97 ± 0.29 |243 | =sleep 0.1= | 105.7 ± 1.6 | 102.3 | 108.0 | 1.00 |322 | =sleep 2= | 2200.0 ± 100.0 | 2100.0 | 2300.0 | 11.00 ± 5.52 |323 | =sleep 0.1= | 200.0 ± 100.0 | 100.0 | 300.0 | 1.00 |324 "#);325}326327/// The given time unit (s) is used to set the units for all entries.
2 unmodified lines
330 let results = [331 BenchmarkResult {332 command: String::from("sleep 2"),333 command_with_unused_parameters: String::from("sleep 2"),254 mean: 2.0050,255 stddev: Some(0.0020),256 median: 2.0050,257 user: 0.0009,258 system: 0.0012,259 min: 2.0020,260 max: 2.0080,261 times: Some(vec![2.0, 2.0, 2.0]),262 memory_usage_byte: None,263 exit_codes: vec![Some(0), Some(0), Some(0)],334 measurements: Measurements::new(vec![335 Measurement {336 time_wall_clock: Time::new::<second>(2.01),337 time_user: Time::new::<second>(2.01),338 time_system: Time::zero(),339 peak_memory_usage: Information::new::<byte>(1024.),340 exit_status: ExitStatus::default(),341 },342 Measurement {343 time_wall_clock: Time::new::<second>(2.02),344 time_user: Time::new::<second>(2.02),345 time_system: Time::zero(),346 peak_memory_usage: Information::new::<byte>(1024.),347 exit_status: ExitStatus::default(),348 },349 Measurement {350 time_wall_clock: Time::new::<second>(2.03),351 time_user: Time::new::<second>(2.03),352 time_system: Time::zero(),353 peak_memory_usage: Information::new::<byte>(1024.),354 exit_status: ExitStatus::default(),355 },356 ]),357 parameters: BTreeMap::new(),358 },359 BenchmarkResult {360 command: String::from("sleep 0.1"),361 command_with_unused_parameters: String::from("sleep 0.1"),269 mean: 0.1057,270 stddev: Some(0.0016),271 median: 0.1057,272 user: 0.0009,273 system: 0.0011,274 min: 0.1023,275 max: 0.1080,276 times: Some(vec![0.1, 0.1, 0.1]),277 memory_usage_byte: None,278 exit_codes: vec![Some(0), Some(0), Some(0)],362 measurements: Measurements::new(vec![363 Measurement {364 time_wall_clock: Time::new::<second>(0.11),365 time_user: Time::new::<second>(0.11),366 time_system: Time::zero(),367 peak_memory_usage: Information::new::<byte>(1024.),368 exit_status: ExitStatus::default(),369 },370 Measurement {371 time_wall_clock: Time::new::<second>(0.12),372 time_user: Time::new::<second>(0.12),373 time_system: Time::zero(),374 peak_memory_usage: Information::new::<byte>(1024.),375 exit_status: ExitStatus::default(),376 },377 Measurement {378 time_wall_clock: Time::new::<second>(0.13),379 time_user: Time::new::<second>(0.13),380 time_system: Time::zero(),381 peak_memory_usage: Information::new::<byte>(1024.),382 exit_status: ExitStatus::default(),383 },384 ]),385 parameters: BTreeMap::new(),386 },387 ];388389 insta::assert_snapshot!(get_output::<MarkdownExporter>(&results, Some(TimeUnit::Second), SortOrder::Command), @r#"284 | Command | Mean [s] | Min [s] | Max [s] | Relative |285 |:---|---:|---:|---:|---:|286 | `sleep 2` | 2.005 ± 0.002 | 2.002 | 2.008 | 18.97 ± 0.29 |287 | `sleep 0.1` | 0.106 ± 0.002 | 0.102 | 0.108 | 1.00 |288 "#);390 | Command | Mean [s] | Min [s] | Max [s] | Relative |391 |:---|---:|---:|---:|---:|392 | `sleep 2` | 2.020 ± 0.010 | 2.010 | 2.030 | 16.83 ± 1.41 |393 | `sleep 0.1` | 0.120 ± 0.010 | 0.110 | 0.130 | 1.00 |394 "#);395396 insta::assert_snapshot!(get_output::<MarkdownExporter>(&results, Some(TimeUnit::Second), SortOrder::MeanTime), @r#"291 | Command | Mean [s] | Min [s] | Max [s] | Relative |292 |:---|---:|---:|---:|---:|293 | `sleep 0.1` | 0.106 ± 0.002 | 0.102 | 0.108 | 1.00 |294 | `sleep 2` | 2.005 ± 0.002 | 2.002 | 2.008 | 18.97 ± 0.29 |295 "#);397 | Command | Mean [s] | Min [s] | Max [s] | Relative |398 |:---|---:|---:|---:|---:|399 | `sleep 0.1` | 0.120 ± 0.010 | 0.110 | 0.130 | 1.00 |400 | `sleep 2` | 2.020 ± 0.010 | 2.010 | 2.030 | 16.83 ± 1.41 |401 "#);402403 insta::assert_snapshot!(get_output::<AsciidocExporter>(&results, Some(TimeUnit::Second), SortOrder::Command), @r#"404 [cols="<,>,>,>,>"]405 |===
3 unmodified lines
409 | Max [s] 410 | Relative 411412 | `sleep 2` 307 | 2.005 ± 0.002 308 | 2.002 309 | 2.008 310 | 18.97 ± 0.29 413 | 2.020 ± 0.010 414 | 2.010 415 | 2.030 416 | 16.83 ± 1.41 417418 | `sleep 0.1` 313 | 0.106 ± 0.002 314 | 0.102 315 | 0.108 419 | 0.120 ± 0.010 420 | 0.110 421 | 0.130 422 | 1.00 423 |===424 "#);425}