Unify TimingResult/TimerResult/Measurement
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 f9aa299 · Browse files · 8 files·+272 added−261 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+272 added−261 removed
- other:+272 added−261 removed
Provenance
- Commit
42e75c1- Tree
7b3bbed- Author
David Peter <sharkdp@users.noreply.github.com>- Committer
David Peter <mail@david-peter.de>- Parent
f9aa299
8 files changed+272 added−261 removed
modified:src/benchmark/benchmark_result.rs+1 added-1 removed
36 unmodified lines37 38 impl BenchmarkResult {39 /// The average wall clock time40 pub fn mean_wall_clock_time(&self) -> Second {41- self.measurements.mean()41+ self.measurements.time_wall_clock_mean()42 }43 44 /// The full command line of the program that is being benchmarked, possibly including a list of45 /// parameters that were not used in the command line template.18 unmodified linesmodified:src/benchmark/executor.rs+51 added-50 removed
1 #[cfg(windows)]2 use std::os::windows::process::CommandExt;3 use std::process::ExitStatus;4 5-use crate::benchmark::quantity::mean;5+use crate::benchmark::measurement::Measurement;6+use crate::benchmark::measurement::Measurements;7 use crate::benchmark::quantity::Byte;8 use crate::benchmark::quantity::Second;9 use crate::command::Command;10 use crate::options::{11 CmdFailureAction, CommandInputPolicy, CommandOutputPolicy, Options, OutputStyleOption, Shell,12 };13 use crate::output::progress_bar::get_progress_bar;13-use crate::quantity::{second, Information, Time, Zero};14 use crate::timer::execute_and_measure;15 use crate::util::randomized_environment_offset;16 17-use super::measurement::{Measurement, Measurements};18-17 use anyhow::{bail, Context, Result};18 19 #[derive(Clone, Copy)]20 pub enum BenchmarkIteration {58 unmodified lines79 80 let result = execute_and_measure(command)81 .with_context(|| format!("Failed to run command '{command_name}'"))?;82 85- if !result.exit_status.success() {86- use crate::util::exit_code::extract_exit_code;83+ if command_failure_action == CmdFailureAction::RaiseError && !result.exit_status.success() {84+ let when = match iteration {85+ BenchmarkIteration::NonBenchmarkRun => "a non-benchmark run".to_string(),86+ BenchmarkIteration::Warmup(0) => "the first warmup run".to_string(),87+ BenchmarkIteration::Warmup(i) => format!("warmup iteration {i}"),88+ BenchmarkIteration::Benchmark(0) => "the first benchmark run".to_string(),89+ BenchmarkIteration::Benchmark(i) => format!("benchmark iteration {i}"),90+ };91+ bail!(92+ "{cause} in {when}. Use the '-i'/'--ignore-failure' option if you want to ignore this. \93+ Alternatively, use the '--show-output' option to debug what went wrong.",94+ cause=result.exit_status.code().map_or(95+ "The process has been terminated by a signal".into(),96+ |c| format!("Command terminated with non-zero exit code {c}")97 98 let should_fail = match command_failure_action {99 CmdFailureAction::RaiseError => true,100 CmdFailureAction::IgnoreAllFailures => false,48 unmodified lines149 iteration: BenchmarkIteration,150 command_failure_action: Option<CmdFailureAction>,151 output_policy: &CommandOutputPolicy,152 ) -> Result<Measurement> {143- run_command_and_measure_common(153+ let result = run_command_and_measure_common(154 command.get_command()?,155 iteration,156 command_failure_action.unwrap_or_else(|| self.options.command_failure_action.clone()),157 &self.options.command_input_policy,158 output_policy,159 &command.get_command_line(),160 )?;161 152- Ok((153- TimingResult {154- time_wall_clock: result.time_wall_clock,155- time_user: result.time_user,156- time_system: result.time_system,157- memory_usage_byte: result.memory_usage_byte,158- },159- result.status,160- ))162+ Ok(Measurement {163+ time_wall_clock: result.time_wall_clock,164+ time_user: result.time_user,165+ time_system: result.time_system,166+ peak_memory_usage: result.peak_memory_usage,167+ exit_status: result.exit_status,168+ })169 }170 171 fn calibrate(&mut self) -> Result<()> {172 Ok(())57 unmodified lines230 time231 }232 }233 226- if let Some(spawning_time) = self.shell_spawning_time {234+ if let Some(ref spawning_time) = self.shell_spawning_time {235 result.time_wall_clock =236 ensure_non_negative(result.time_wall_clock - spawning_time.time_wall_clock);237 result.time_user = ensure_non_negative(result.time_user - spawning_time.time_user);238 result.time_system =239 ensure_non_negative(result.time_system - spawning_time.time_system);240 }241 234- Ok((235- TimingResult {236- time_wall_clock: result.time_wall_clock,237- time_user: result.time_user,238- time_system: result.time_system,239- memory_usage_byte: result.memory_usage_byte,240- },241- result.status,242- ))242+ Ok(Measurement {243+ time_wall_clock: result.time_wall_clock,244+ time_user: result.time_user,245+ time_system: result.time_system,246+ peak_memory_usage: result.peak_memory_usage,247+ exit_status: result.exit_status,248+ })249 }250 251 /// Measure the average shell spawning time252 fn calibrate(&mut self) -> Result<()> {7 unmodified lines260 } else {261 None262 };263 258- let mut times_wall_clock: Vec<Second> = vec![]; // TODO259- let mut times_user: Vec<Second> = vec![];260- let mut times_system: Vec<Second> = vec![];264+ let mut measurements = Measurements::default();265 266 for _ in 0..COUNT {267 // Just run the shell without any command264- let res = self.run_command_and_measure(268+ let measurement = self.run_command_and_measure(269 &Command::new(None, ""),270 BenchmarkIteration::NonBenchmarkRun,271 None,272 &CommandOutputPolicy::Null,273 );274 271- match res {275+ match measurement {276 Err(_) => {277 let shell_cmd = if cfg!(windows) {278 format!("{} /C \"\"", self.shell)279 } else {4 unmodified lines284 "Could not measure shell execution time. Make sure you can run '{}'.",285 shell_cmd286 );287 }284- Ok((r, _)) => {285- times_wall_clock.push(r.time_wall_clock);286- times_user.push(r.time_user);287- times_system.push(r.time_system);288+ Ok(result) => {289+ measurements.push(result);290 }291 }292 293 if let Some(bar) = progress_bar.as_ref() {4 unmodified lines298 if let Some(bar) = progress_bar.as_ref() {299 bar.finish_and_clear()300 }301 300- self.shell_spawning_time = Some(TimingResult {301- time_wall_clock: mean(×_wall_clock),302- time_user: mean(×_user),303- time_system: mean(×_system),304- memory_usage_byte: Byte::new(0),302+ self.shell_spawning_time = Some(Measurement {303+ time_wall_clock: measurements.time_wall_clock_mean(),304+ time_user: measurements.time_user_mean(),305+ time_system: measurements.time_system_mean(),306+ peak_memory_usage: measurements.peak_memory_usage_mean(),307+ exit_status: ExitStatus::default(),308 });309 310 Ok(())311 }312 313 fn time_overhead(&self) -> Second {311- self.shell_spawning_time.unwrap().time_wall_clock314+ self.shell_spawning_time.as_ref().unwrap().time_wall_clock315 }316 }317 318 #[derive(Clone)]37 unmodified lines356 use std::os::windows::process::ExitStatusExt;357 ExitStatus::from_raw(0)358 };359 357- Ok((358- TimingResult {359- time_wall_clock: Self::extract_time(command.get_command_line()),360- time_user: Second::zero(),361- time_system: Second::zero(),362- memory_usage_byte: Byte::new(0),363- },364- status,365- ))360+ Ok(Measurement {361+ time_wall_clock: Self::extract_time(command.get_command_line()),362+ time_user: Second::zero(),363+ time_system: Second::zero(),364+ peak_memory_usage: Byte::new(0),365+ exit_status,366+ })367 }368 369 fn calibrate(&mut self) -> Result<()> {370 Ok(())14 unmodified linesmodified:src/benchmark/measurement.rs+35 added-13 removed
1+use std::process::ExitStatus;2+3 use serde::Serialize;4 5 use crate::benchmark::quantity::{max, mean, median, min, standard_deviation, Byte, Second};6 use crate::outlier_detection::modified_zscores;7+use crate::util::exit_code::extract_exit_code;8 9+fn serialize_exit_status<S>(exit_status: &ExitStatus, serializer: S) -> Result<S::Ok, S::Error>10+where11+ S: serde::Serializer,12+{13+ match extract_exit_code(*exit_status) {14+ Some(code) => serializer.serialize_i32(code),15+ None => serializer.serialize_unit(),16+ }17+}18+19 /// Performance metric measurements and exit code for a single run7-#[derive(Debug, Clone, Serialize, PartialEq)]20+#[derive(Debug, Clone, Default, Serialize, PartialEq)]21 pub struct Measurement {22 /// Elapsed wall clock time (real time)10- pub wall_clock_time: Second,23+ pub time_wall_clock: Second,24 25 /// Time spent in user mode13- pub user_time: Second,26+ pub time_user: Second,27 28 /// Time spent in kernel mode16- pub system_time: Second,29+ pub time_system: Second,30 31 /// Maximum memory usage of the process19- pub memory_usage_byte: Byte,32+ pub peak_memory_usage: Byte,33 21- /// Exit codes of the process22- pub exit_code: Option<i32>,34+ // The exit status of the process35+ #[serde(serialize_with = "serialize_exit_status")]36+ pub exit_status: ExitStatus,37 }38 39 #[derive(Debug, Default, Clone, Serialize, PartialEq)]40 pub struct Measurements {19 unmodified lines60 61 pub fn wall_clock_times(&self) -> Vec<Second> {62 self.measurements63 .iter()50- .map(|m| m.wall_clock_time)64+ .map(|m| m.time_wall_clock)65 .collect()66 }67 68 /// The average wall clock time55- pub fn mean(&self) -> Second {69+ pub fn time_wall_clock_mean(&self) -> Second {70 mean(&self.wall_clock_times())71 }72 73 /// The standard deviation of all wall clock times. Not available if only one run has been performed22 unmodified lines96 max(&self.wall_clock_times())97 }98 99 /// The average user time86- pub fn user_mean(&self) -> Second {100+ pub fn time_user_mean(&self) -> Second {101 mean(102 &self103 .measurements104 .iter()91- .map(|m| m.user_time)105+ .map(|m| m.time_user)106 .collect::<Vec<_>>(),107 )108 }109 110 /// The average system time97- pub fn system_mean(&self) -> Second {111+ pub fn time_system_mean(&self) -> Second {112 mean(113 &self114 .measurements115 .iter()102- .map(|m| m.system_time)116+ .map(|m| m.time_system)117 .collect::<Vec<_>>(),118 )119 }120 121+ pub fn peak_memory_usage_mean(&self) -> Byte {122+ self.measurements123+ .iter()124+ .map(|m| m.peak_memory_usage)125+ .max_by(|a, b| a.partial_cmp(b).unwrap()) // TODO126+ .unwrap() // TODO127+ }128+129 pub fn modified_zscores(&self) -> Vec<f64> {130 modified_zscores(131 &self132 .wall_clock_times()10 unmodified linesmodified:src/benchmark/mod.rs+22 added-24 removed
23 unmodified lines24 finish_initial_measurement, get_progress_bar, start_initial_measurement,25 };26 use crate::output::warnings::{OutlierWarningOptions, Warnings};27 use crate::parameter::ParameterNameAndValue;28-use crate::quantity::{byte, const_time_from_seconds, ratio, second, FormatQuantity, Time, Zero};29-use crate::util::exit_code::extract_exit_code;28 use benchmark_result::BenchmarkResult;31-use measurement::{Measurement, Measurements};29 30 use anyhow::{anyhow, Result};31 use colored::*;32 236 unmodified lines269 // Initial timing run270 if let Some(bar) = progress_bar.as_ref() {271 start_initial_measurement(bar, Instant::now());272 }276- let res = self.executor.run_command_and_measure(273+ let result = self.executor.run_command_and_measure(274 self.command,275 benchmark_iteration,276 None,277 output_policy,278 )?;282- let success = res.exit_status.success();279+ let success = result.exit_status.success();280 281 if let Some(bar) = progress_bar.as_ref() {282 let time_unit = self283 .options284 .time_unit288- .unwrap_or(res.time_wall_clock.suitable_unit());289- let estimate = res.time_wall_clock.format(time_unit);285+ .unwrap_or(result.time_wall_clock.suitable_unit());286+ let estimate = result.time_wall_clock.format(time_unit);287 finish_initial_measurement(288 bar,289 format!("Current estimate: {}", estimate.to_string().green()),290 );5 unmodified lines296 });297 298 // Determine number of benchmark runs299 let runs_in_min_time = (self.options.min_benchmarking_time303- / (res.time_wall_clock300+ / (result.time_wall_clock301 + self.executor.time_overhead()302 + preparation_overhead303 + conclusion_overhead))304 .get::<ratio>() as u64;12 unmodified lines317 let count_remaining = count - 1;318 319 // Save the first result320 measurements.push(Measurement {324- wall_clock_time: res.time_wall_clock,325- user_time: res.time_user,326- system_time: res.time_system,327- memory_usage_byte: res.memory_usage_byte,328- exit_code: extract_exit_code(status),321+ time_wall_clock: result.time_wall_clock,322+ time_user: result.time_user,323+ time_system: result.time_system,324+ peak_memory_usage: result.peak_memory_usage,325+ exit_status: result.exit_status,326 });327 328 all_succeeded = all_succeeded && success;329 7 unmodified lines337 for i in 0..count_remaining {338 let benchmark_iteration = BenchmarkIteration::Benchmark(i + 1);339 340 let msg = {344- let mean = format_duration(measurements.mean(), self.options.time_unit);341+ let mean =342+ format_duration(measurements.time_wall_clock_mean(), self.options.time_unit);343 format!("Current estimate: {}", mean.to_string().green())344 };345 346 if let Some(bar) = progress_bar.as_ref() {1 unmodified line348 }349 350 run_preparation_command(benchmark_iteration)?;351 354- let res = self.executor.run_command_and_measure(352+ let result = self.executor.run_command_and_measure(353 self.command,354 benchmark_iteration,355 None,356 output_policy,357 )?;360- let success = res.exit_status.success();358+ let success = result.exit_status.success();359 360 measurements.push(Measurement {363- wall_clock_time: res.time_wall_clock,364- user_time: res.time_user,365- system_time: res.time_system,366- memory_usage_byte: res.memory_usage_byte,367- exit_code: extract_exit_code(status),361+ time_wall_clock: result.time_wall_clock,362+ time_user: result.time_user,363+ time_system: result.time_system,364+ peak_memory_usage: result.peak_memory_usage,365+ exit_status: result.exit_status,366 });367 368 all_succeeded = all_succeeded && success;369 9 unmodified lines379 }380 381 // Formatting and console output382 let (mean_str, time_unit) =385- format_duration_unit(measurements.mean(), self.options.time_unit);383+ format_duration_unit(measurements.time_wall_clock_mean(), self.options.time_unit);384 let min_str = format_duration(measurements.min(), Some(time_unit));385 let max_str = format_duration(measurements.max(), Some(time_unit));386 let num_str = format!("{num_runs} runs", num_runs = measurements.len());387 390- let user_str = format_duration(measurements.user_mean(), Some(time_unit));391- let system_str = format_duration(measurements.system_mean(), Some(time_unit));388+ let user_str = format_duration(measurements.time_user_mean(), Some(time_unit));389+ let system_str = format_duration(measurements.time_system_mean(), Some(time_unit));390 391 if self.options.output_style != OutputStyleOption::Disabled {392 if measurements.len() == 1 {393 println!(109 unmodified linesmodified:src/benchmark/relative_speed.rs+6 added-6 removed
146 unmodified lines147 }148 149 #[cfg(test)]150 fn create_result(name: &str, mean: f64) -> BenchmarkResult {151- use std::collections::BTreeMap;151+ use std::{collections::BTreeMap, process::ExitStatus};152 153 use crate::benchmark::{154 measurement::{Measurement, Measurements},155 quantity::Byte,2 unmodified lines158 BenchmarkResult {159 command: name.into(),160 measurements: Measurements {161 measurements: vec![Measurement {162- wall_clock_time: Second::new(mean),163- user_time: Second::new(mean),164- system_time: Second::zero(),165- memory_usage_byte: Byte::new(1024),166- exit_code: Some(0),162+ time_wall_clock: Second::new(mean),163+ time_user: Second::new(mean),164+ time_system: Second::zero(),165+ peak_memory_usage: Byte::new(1024),166+ exit_status: ExitStatus::default(),167 }],168 },169 parameters: BTreeMap::new(),170 }66 unmodified linesmodified:src/export/csv.rs+33 added-32 removed
46 unmodified lines47 for f in &[48 res.mean_wall_clock_time(),49 res.measurements.stddev().unwrap_or_default(),50 res.measurements.median(),51- res.measurements.user_mean(),52- res.measurements.system_mean(),51+ res.measurements.time_user_mean(),52+ res.measurements.time_system_mean(),53 res.measurements.min(),54 res.measurements.max(),55 ] {56 fields.push(Cow::Owned(f.value_in::<Second>().to_string().into_bytes()))14 unmodified lines71 use crate::benchmark::measurement::{Measurement, Measurements};72 use crate::benchmark::quantity::{Byte, Second};73 74 use std::collections::BTreeMap;75+ use std::process::ExitStatus;76 77 let exporter = CsvExporter::default();78 79 let results = vec![80 BenchmarkResult {81 command: String::from("command_a"),82 measurements: Measurements::new(vec![83 Measurement {83- wall_clock_time: Second::new(7.0),84- user_time: Second::new(7.0),85- system_time: Second::zero(),86- memory_usage_byte: Byte::new(1024),87- exit_code: Some(0),84+ time_wall_clock: Second::new(7.0),85+ time_user: Second::new(7.0),86+ time_system: Second::zero(),87+ peak_memory_usage: Byte::new(1024),88+ exit_status: ExitStatus::default(),89 },90 Measurement {90- wall_clock_time: Second::new(8.0),91- user_time: Second::new(8.0),92- system_time: Second::zero(),93- memory_usage_byte: Byte::new(1024),94- exit_code: Some(0),91+ time_wall_clock: Second::new(8.0),92+ time_user: Second::new(8.0),93+ time_system: Second::zero(),94+ peak_memory_usage: Byte::new(1024),95+ exit_status: ExitStatus::default(),96 },97 Measurement {97- wall_clock_time: Second::new(12.0),98- user_time: Second::new(12.0),99- system_time: Second::zero(),100- memory_usage_byte: Byte::new(1024),101- exit_code: Some(0),98+ time_wall_clock: Second::new(12.0),99+ time_user: Second::new(12.0),100+ time_system: Second::zero(),101+ peak_memory_usage: Byte::new(1024),102+ exit_status: ExitStatus::default(),103 },104 ]),105 parameters: {106 let mut params = BTreeMap::new();17 unmodified lines124 BenchmarkResult {125 command: String::from("command_b"),126 measurements: Measurements::new(vec![127 Measurement {127- wall_clock_time: Second::new(17.0),128- user_time: Second::new(17.0),129- system_time: Second::zero(),130- memory_usage_byte: Byte::new(1024),131- exit_code: Some(0),128+ time_wall_clock: Second::new(17.0),129+ time_user: Second::new(17.0),130+ time_system: Second::zero(),131+ peak_memory_usage: Byte::new(1024),132+ exit_status: ExitStatus::default(),133 },134 Measurement {134- wall_clock_time: Second::new(18.0),135- user_time: Second::new(18.0),136- system_time: Second::zero(),137- memory_usage_byte: Byte::new(1024),138- exit_code: Some(0),135+ time_wall_clock: Second::new(18.0),136+ time_user: Second::new(18.0),137+ time_system: Second::zero(),138+ peak_memory_usage: Byte::new(1024),139+ exit_status: ExitStatus::default(),140 },141 Measurement {141- wall_clock_time: Second::new(19.0),142- user_time: Second::new(19.0),143- system_time: Second::zero(),144- memory_usage_byte: Byte::new(1024),145- exit_code: Some(0),142+ time_wall_clock: Second::new(19.0),143+ time_user: Second::new(19.0),144+ time_system: Second::zero(),145+ peak_memory_usage: Byte::new(1024),146+ exit_status: ExitStatus::default(),147 },148 ]),149 parameters: {150 let mut params = BTreeMap::new();32 unmodified linesmodified:src/export/tests.rs+120 added-120 removed
29 unmodified lines30 BenchmarkResult {31 command: String::from("sleep 0.1"),32 measurements: Measurements::new(vec![33 Measurement {34- wall_clock_time: Second::new(0.09),35- user_time: Second::new(0.09),36- system_time: Second::zero(),37- memory_usage_byte: Byte::new(1024),38- exit_code: Some(0),34+ time_wall_clock: Second::new(0.09),35+ time_user: Second::new(0.09),36+ time_system: Second::zero(),37+ peak_memory_usage: Byte::new(1024),38+ exit_status: ExitStatus::default(),39 },40 Measurement {41- wall_clock_time: Second::new(0.10),42- user_time: Second::new(0.10),43- system_time: Second::zero(),44- memory_usage_byte: Byte::new(1024),45- exit_code: Some(0),41+ time_wall_clock: Second::new(0.10),42+ time_user: Second::new(0.10),43+ time_system: Second::zero(),44+ peak_memory_usage: Byte::new(1024),45+ exit_status: ExitStatus::default(),46 },47 Measurement {48- wall_clock_time: Second::new(0.14),49- user_time: Second::new(0.14),50- system_time: Second::zero(),51- memory_usage_byte: Byte::new(1024),52- exit_code: Some(0),48+ time_wall_clock: Second::new(0.14),49+ time_user: Second::new(0.14),50+ time_system: Second::zero(),51+ peak_memory_usage: Byte::new(1024),52+ exit_status: ExitStatus::default(),53 },54 ]),55 parameters: BTreeMap::new(),56 },57 BenchmarkResult {58 command: String::from("sleep 2"),59 measurements: Measurements::new(vec![60 Measurement {61- wall_clock_time: Second::new(2.0),62- user_time: Second::new(2.0),63- system_time: Second::zero(),64- memory_usage_byte: Byte::new(1024),65- exit_code: Some(0),61+ time_wall_clock: Second::new(2.0),62+ time_user: Second::new(2.0),63+ time_system: Second::zero(),64+ peak_memory_usage: Byte::new(1024),65+ exit_status: ExitStatus::default(),66 },67 Measurement {68- wall_clock_time: Second::new(3.0),69- user_time: Second::new(3.0),70- system_time: Second::zero(),71- memory_usage_byte: Byte::new(1024),72- exit_code: Some(0),68+ time_wall_clock: Second::new(3.0),69+ time_user: Second::new(3.0),70+ time_system: Second::zero(),71+ peak_memory_usage: Byte::new(1024),72+ exit_status: ExitStatus::default(),73 },74 Measurement {75- wall_clock_time: Second::new(4.0),76- user_time: Second::new(4.0),77- system_time: Second::zero(),78- memory_usage_byte: Byte::new(1024),79- exit_code: Some(0),75+ time_wall_clock: Second::new(4.0),76+ time_user: Second::new(4.0),77+ time_system: Second::zero(),78+ peak_memory_usage: Byte::new(1024),79+ exit_status: ExitStatus::default(),80 },81 ]),82 parameters: BTreeMap::new(),83 },45 unmodified lines129 BenchmarkResult {130 command: String::from("sleep 2"),131 measurements: Measurements::new(vec![132 Measurement {133- wall_clock_time: Second::new(2.1),134- user_time: Second::new(2.1),135- system_time: Second::zero(),136- memory_usage_byte: Byte::new(1024),137- exit_code: Some(0),133+ time_wall_clock: Second::new(2.1),134+ time_user: Second::new(2.1),135+ time_system: Second::zero(),136+ peak_memory_usage: Byte::new(1024),137+ exit_status: ExitStatus::default(),138 },139 Measurement {140- wall_clock_time: Second::new(2.2),141- user_time: Second::new(2.2),142- system_time: Second::zero(),143- memory_usage_byte: Byte::new(1024),144- exit_code: Some(0),140+ time_wall_clock: Second::new(2.2),141+ time_user: Second::new(2.2),142+ time_system: Second::zero(),143+ peak_memory_usage: Byte::new(1024),144+ exit_status: ExitStatus::default(),145 },146 Measurement {147- wall_clock_time: Second::new(2.3),148- user_time: Second::new(2.3),149- system_time: Second::zero(),150- memory_usage_byte: Byte::new(1024),151- exit_code: Some(0),147+ time_wall_clock: Second::new(2.3),148+ time_user: Second::new(2.3),149+ time_system: Second::zero(),150+ peak_memory_usage: Byte::new(1024),151+ exit_status: ExitStatus::default(),152 },153 ]),154 parameters: BTreeMap::new(),155 },156 BenchmarkResult {157 command: String::from("sleep 0.1"),158 measurements: Measurements::new(vec![159 Measurement {160- wall_clock_time: Second::new(0.1),161- user_time: Second::new(0.1),162- system_time: Second::zero(),163- memory_usage_byte: Byte::new(1024),164- exit_code: Some(0),160+ time_wall_clock: Second::new(0.1),161+ time_user: Second::new(0.1),162+ time_system: Second::zero(),163+ peak_memory_usage: Byte::new(1024),164+ exit_status: ExitStatus::default(),165 },166 Measurement {167- wall_clock_time: Second::new(0.2),168- user_time: Second::new(0.2),169- system_time: Second::zero(),170- memory_usage_byte: Byte::new(1024),171- exit_code: Some(0),167+ time_wall_clock: Second::new(0.2),168+ time_user: Second::new(0.2),169+ time_system: Second::zero(),170+ peak_memory_usage: Byte::new(1024),171+ exit_status: ExitStatus::default(),172 },173 Measurement {174- wall_clock_time: Second::new(0.3),175- user_time: Second::new(0.3),176- system_time: Second::zero(),177- memory_usage_byte: Byte::new(1024),178- exit_code: Some(0),174+ time_wall_clock: Second::new(0.3),175+ time_user: Second::new(0.3),176+ time_system: Second::zero(),177+ peak_memory_usage: Byte::new(1024),178+ exit_status: ExitStatus::default(),179 },180 ]),181 parameters: BTreeMap::new(),182 },45 unmodified lines228 BenchmarkResult {229 command: String::from("sleep 2"),230 measurements: Measurements::new(vec![231 Measurement {232- wall_clock_time: Second::new(2.1),233- user_time: Second::new(2.1),234- system_time: Second::zero(),235- memory_usage_byte: Byte::new(1024),236- exit_code: Some(0),232+ time_wall_clock: Second::new(2.1),233+ time_user: Second::new(2.1),234+ time_system: Second::zero(),235+ peak_memory_usage: Byte::new(1024),236+ exit_status: ExitStatus::default(),237 },238 Measurement {239- wall_clock_time: Second::new(2.2),240- user_time: Second::new(2.2),241- system_time: Second::zero(),242- memory_usage_byte: Byte::new(1024),243- exit_code: Some(0),239+ time_wall_clock: Second::new(2.2),240+ time_user: Second::new(2.2),241+ time_system: Second::zero(),242+ peak_memory_usage: Byte::new(1024),243+ exit_status: ExitStatus::default(),244 },245 Measurement {246- wall_clock_time: Second::new(2.3),247- user_time: Second::new(2.3),248- system_time: Second::zero(),249- memory_usage_byte: Byte::new(1024),250- exit_code: Some(0),246+ time_wall_clock: Second::new(2.3),247+ time_user: Second::new(2.3),248+ time_system: Second::zero(),249+ peak_memory_usage: Byte::new(1024),250+ exit_status: ExitStatus::default(),251 },252 ]),253 parameters: BTreeMap::new(),254 },255 BenchmarkResult {256 command: String::from("sleep 0.1"),257 measurements: Measurements::new(vec![258 Measurement {259- wall_clock_time: Second::new(0.1),260- user_time: Second::new(0.1),261- system_time: Second::zero(),262- memory_usage_byte: Byte::new(1024),263- exit_code: Some(0),259+ time_wall_clock: Second::new(0.1),260+ time_user: Second::new(0.1),261+ time_system: Second::zero(),262+ peak_memory_usage: Byte::new(1024),263+ exit_status: ExitStatus::default(),264 },265 Measurement {266- wall_clock_time: Second::new(0.2),267- user_time: Second::new(0.2),268- system_time: Second::zero(),269- memory_usage_byte: Byte::new(1024),270- exit_code: Some(0),266+ time_wall_clock: Second::new(0.2),267+ time_user: Second::new(0.2),268+ time_system: Second::zero(),269+ peak_memory_usage: Byte::new(1024),270+ exit_status: ExitStatus::default(),271 },272 Measurement {273- wall_clock_time: Second::new(0.3),274- user_time: Second::new(0.3),275- system_time: Second::zero(),276- memory_usage_byte: Byte::new(1024),277- exit_code: Some(0),273+ time_wall_clock: Second::new(0.3),274+ time_user: Second::new(0.3),275+ time_system: Second::zero(),276+ peak_memory_usage: Byte::new(1024),277+ exit_status: ExitStatus::default(),278 },279 ]),280 parameters: BTreeMap::new(),281 },44 unmodified lines326 BenchmarkResult {327 command: String::from("sleep 2"),328 measurements: Measurements::new(vec![329 Measurement {330- wall_clock_time: Second::new(2.01),331- user_time: Second::new(2.01),332- system_time: Second::zero(),333- memory_usage_byte: Byte::new(1024),334- exit_code: Some(0),330+ time_wall_clock: Second::new(2.01),331+ time_user: Second::new(2.01),332+ time_system: Second::zero(),333+ peak_memory_usage: Byte::new(1024),334+ exit_status: ExitStatus::default(),335 },336 Measurement {337- wall_clock_time: Second::new(2.02),338- user_time: Second::new(2.02),339- system_time: Second::zero(),340- memory_usage_byte: Byte::new(1024),341- exit_code: Some(0),337+ time_wall_clock: Second::new(2.02),338+ time_user: Second::new(2.02),339+ time_system: Second::zero(),340+ peak_memory_usage: Byte::new(1024),341+ exit_status: ExitStatus::default(),342 },343 Measurement {344- wall_clock_time: Second::new(2.03),345- user_time: Second::new(2.03),346- system_time: Second::zero(),347- memory_usage_byte: Byte::new(1024),348- exit_code: Some(0),344+ time_wall_clock: Second::new(2.03),345+ time_user: Second::new(2.03),346+ time_system: Second::zero(),347+ peak_memory_usage: Byte::new(1024),348+ exit_status: ExitStatus::default(),349 },350 ]),351 parameters: BTreeMap::new(),352 },353 BenchmarkResult {354 command: String::from("sleep 0.1"),355 measurements: Measurements::new(vec![356 Measurement {357- wall_clock_time: Second::new(0.11),358- user_time: Second::new(0.11),359- system_time: Second::zero(),360- memory_usage_byte: Byte::new(1024),361- exit_code: Some(0),357+ time_wall_clock: Second::new(0.11),358+ time_user: Second::new(0.11),359+ time_system: Second::zero(),360+ peak_memory_usage: Byte::new(1024),361+ exit_status: ExitStatus::default(),362 },363 Measurement {364- wall_clock_time: Second::new(0.12),365- user_time: Second::new(0.12),366- system_time: Second::zero(),367- memory_usage_byte: Byte::new(1024),368- exit_code: Some(0),364+ time_wall_clock: Second::new(0.12),365+ time_user: Second::new(0.12),366+ time_system: Second::zero(),367+ peak_memory_usage: Byte::new(1024),368+ exit_status: ExitStatus::default(),369 },370 Measurement {371- wall_clock_time: Second::new(0.13),372- user_time: Second::new(0.13),373- system_time: Second::zero(),374- memory_usage_byte: Byte::new(1024),375- exit_code: Some(0),371+ time_wall_clock: Second::new(0.13),372+ time_user: Second::new(0.13),373+ time_system: Second::zero(),374+ peak_memory_usage: Byte::new(1024),375+ exit_status: ExitStatus::default(),376 },377 ]),378 parameters: BTreeMap::new(),379 },39 unmodified linesmodified:src/timer/mod.rs+4 added-15 removed
14 unmodified lines15 16 #[cfg(target_os = "windows")]17 use windows_sys::Win32::System::Threading::CREATE_SUSPENDED;18 19-use crate::benchmark::quantity::{Byte, Second};19+use crate::benchmark::measurement::Measurement;20 use wall_clock_timer::WallClockTimer;21 22 use std::io::Read;23 use std::process::{ChildStdout, Command};24 25 use anyhow::Result;26 27-/// Used to indicate the result of running a command28-#[derive(Debug, Copy, Clone)]29-pub struct TimerResult {30- pub time_wall_clock: Second,31- pub time_user: Second,32- pub time_system: Second,33- pub memory_usage_byte: Byte,34- /// The exit status of the process35- pub status: ExitStatus,36-}37-27 /// Discard the output of a child process.28 fn discard(output: ChildStdout) {29 const CHUNK_SIZE: usize = 64 << 10;30 50 unmodified lines81 // Handle CommandOutputPolicy::Pipe82 discard(output);83 }84 96- let (status, time_user, time_system, memory_usage_byte) = cpu_timer.stop(child)?;85+ let (exit_status, time_user, time_system, memory_usage_byte) = cpu_timer.stop(child)?;86 let time_wall_clock = wallclock_timer.stop();87 99- Ok(TimerResult {88+ Ok(Measurement {89 time_wall_clock,90 time_user,91 time_system,103- peak_memory_usage,92+ peak_memory_usage: memory_usage_byte,93 exit_status,94 })95 }