Skip to content
Myr

Real => wall clock

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 af4422d · Browse files · 7 files+122 added−97 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+122 added−97 removed

  • other:+122 added−97 removed

7 files+122 added−97 removed

modified:src/benchmark/benchmark_result.rs+6 added-6 removed
6 unmodified lines
7 min_max::{max, min},8 units::Second,9};1011/// Performance metrics and exit codes for each run12#[derive(Debug, Default, Clone, Serialize, PartialEq)]12pub struct BenchmarkRun {13pub struct Run {14 /// Wall clock time measurement15 pub wall_clock_time: Second,1617 /// Time spent in user mode
8 unmodified lines
26 /// Exit codes of the process27 pub exit_code: Option<i32>,28}2930/// Parameter value and whether it was used in the command line template31#[derive(Debug, Default, Clone, Serialize, PartialEq)]32pub struct Parameter {33 pub value: String,34 pub is_unused: bool,35}3635/// 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.37/// Meta data and performance metrics for a single benchmark38#[derive(Debug, Default, Clone, Serialize, PartialEq)]39#[serde(transparent)]40pub struct Parameter {41 pub value: String,
6 unmodified lines
48pub struct BenchmarkResult {49 /// The full command line of the program that is being benchmarked50 pub command: String,5152 /// All run time measurements53 pub runs: Vec<BenchmarkRun>,52 /// Performance metrics and exit codes for each run53 pub runs: Vec<Run>,5455 /// Parameter values for this benchmark56 #[serde(skip_serializing_if = "BTreeMap::is_empty")]57 pub parameters: BTreeMap<String, Parameter>,
79 unmodified lines
modified:src/benchmark/executor.rs+45 added-22 removed
142 unmodified lines
143 command_failure_action.unwrap_or_else(|| self.options.command_failure_action.clone()),144 &self.options.command_input_policy,145 output_policy,146 &command.get_command_line(),147 )147 )?;148149 Ok((150 TimingResult {151 time_wall_clock: result.time_wall_clock,152 time_user: result.time_user,153 time_system: result.time_system,154 memory_usage_byte: result.memory_usage_byte,155 },156 result.status,157 ))158 }159160 fn calibrate(&mut self) -> Result<()> {161 Ok(())
51 unmodified lines
213214 // Subtract shell spawning time215 if let Some(spawning_time) = self.shell_spawning_time {216 result.time_wall_clock =207 (result.time_wall_clock - spawning_time.time_wall_clock).max(Time::zero());208 result.time_user = (result.time_user - spawning_time.time_user).max(Time::zero());209 result.time_system = (result.time_system - spawning_time.time_system).max(Time::zero());217 (result.time_wall_clock - spawning_time.time_wall_clock).max(0.0);218 result.time_user = (result.time_user - spawning_time.time_user).max(0.0);219 result.time_system = (result.time_system - spawning_time.time_system).max(0.0);220 }221212 Ok(result)222 Ok((223 TimingResult {224 time_wall_clock: result.time_wall_clock,225 time_user: result.time_user,226 time_system: result.time_system,227 memory_usage_byte: result.memory_usage_byte,228 },229 result.status,230 ))231 }232233 /// Measure the average shell spawning time234 fn calibrate(&mut self) -> Result<()> {
7 unmodified lines
242 } else {243 None244 };245228 let mut measurements = Measurements::default();246 let mut times_wall_clock: Vec<Second> = vec![];247 let mut times_user: Vec<Second> = vec![];248 let mut times_system: Vec<Second> = vec![];249250 for _ in 0..COUNT {251 // Just run the shell without any command252 let res = self.run_command_and_measure(
15 unmodified lines
268 "Could not measure shell execution time. Make sure you can run '{}'.",269 shell_cmd270 );271 }252 Ok(r) => {253 measurements.push(r);272 Ok((r, _)) => {273 times_wall_clock.push(r.time_wall_clock);274 times_user.push(r.time_user);275 times_system.push(r.time_system);276 }277 }278279 if let Some(bar) = progress_bar.as_ref() {
4 unmodified lines
284 if let Some(bar) = progress_bar.as_ref() {285 bar.finish_and_clear()286 }287266 self.shell_spawning_time = Some(Measurement {267 time_wall_clock: measurements.time_wall_clock_mean(),268 time_user: measurements.time_user_mean(),269 time_system: measurements.time_system_mean(),270 peak_memory_usage: measurements.peak_memory_usage_mean(),271 exit_status: ExitStatus::default(),288 self.shell_spawning_time = Some(TimingResult {289 time_wall_clock: mean(&times_wall_clock),290 time_user: mean(&times_user),291 time_system: mean(&times_system),292 memory_usage_byte: 0,293 });294295 Ok(())296 }297277 fn time_overhead(&self) -> Time {298 fn time_overhead(&self) -> Second {299 self.shell_spawning_time.unwrap().time_wall_clock300 }301}302
38 unmodified lines
341 use std::os::windows::process::ExitStatusExt;342 ExitStatus::from_raw(0)343 };344324 Ok(Measurement {325 time_wall_clock: Self::extract_time(command.get_command_line()),326 time_user: Time::zero(),327 time_system: Time::zero(),328 peak_memory_usage: Information::zero(),329 exit_status,330 })345 Ok((346 TimingResult {347 time_wall_clock: Self::extract_time(command.get_command_line()),348 time_user: 0.0,349 time_system: 0.0,350 memory_usage_byte: 0,351 },352 status,353 ))354 }355356 fn calibrate(&mut self) -> Result<()> {357 Ok(())
17 unmodified lines
modified:src/benchmark/mod.rs+34 added-32 removed
6 unmodified lines
7use std::cmp;8use std::io::{self, Write};9use std::time::Instant;1011use crate::benchmark::benchmark_result::{BenchmarkRun, Parameter};11use crate::benchmark::benchmark_result::{Parameter, Run};12use crate::benchmark::executor::BenchmarkIteration;13use crate::command::Command;14use crate::options::{15 CmdFailureAction, CommandOutputPolicy, ExecutorKind, Options, OutputStyleOption,
151 unmodified lines
167 self.command.get_name_with_unused_parameters(),168 )?;169 }170171 let mut measurements = Measurements::default();171 let mut times_wall_clock: Vec<Second> = vec![];172 let mut times_user: Vec<Second> = vec![];173 let mut times_system: Vec<Second> = vec![];174 let mut memory_usage_byte: Vec<u64> = vec![];175 let mut exit_codes: Vec<Option<i32>> = vec![];176 let mut all_succeeded = true;177178 let output_policy = &self.options.command_output_policies[self.number];179
83 unmodified lines
263 } else {264 None265 };266263 let benchmark_iteration = BenchmarkIteration::Benchmark(0);264 let preparation_result = run_preparation_command(benchmark_iteration)?;265 let preparation_overhead = preparation_result.map_or(Time::zero(), |res| {267 let preparation_result = run_preparation_command()?;268 let preparation_overhead = preparation_result.map_or(0.0, |res| {269 res.time_wall_clock + self.executor.time_overhead()270 });271272 // Initial timing run
19 unmodified lines
292 format!("Current estimate: {}", estimate.to_string().green()),293 );294 }295293 let conclusion_result = run_conclusion_command(benchmark_iteration)?;294 let conclusion_overhead = conclusion_result.map_or(Time::zero(), |res| {296 let conclusion_result = run_conclusion_command()?;297 let conclusion_overhead = conclusion_result.map_or(0.0, |res| {298 res.time_wall_clock + self.executor.time_overhead()299 });300301 // Determine number of benchmark runs
17 unmodified lines
319320 let count_remaining = count - 1;321322 // Save the first result320 measurements.push(res);323 times_wall_clock.push(res.time_wall_clock);324 times_user.push(res.time_user);325 times_system.push(res.time_system);326 memory_usage_byte.push(res.memory_usage_byte);327 exit_codes.push(extract_exit_code(status));328329 all_succeeded = all_succeeded && success;330331 // Re-configure the progress bar
6 unmodified lines
338 for i in 0..count_remaining {339 let benchmark_iteration = BenchmarkIteration::Benchmark(i + 1);340341 let msg = {335 let t_wall_clock_mean = measurements.time_wall_clock_mean();336 let time_unit = self337 .options338 .time_unit339 .unwrap_or(t_wall_clock_mean.suitable_unit());340 let mean = t_wall_clock_mean.format(time_unit);342 let mean = format_duration(mean(&times_wall_clock), self.options.time_unit);343 format!("Current estimate: {}", mean.to_string().green())344 };345346 if let Some(bar) = progress_bar.as_ref() {
9 unmodified lines
356 output_policy,357 )?;358 let success = res.exit_status.success();359358 measurements.push(res);360 times_wall_clock.push(res.time_wall_clock);361 times_user.push(res.time_user);362 times_system.push(res.time_system);363 memory_usage_byte.push(res.memory_usage_byte);364 exit_codes.push(extract_exit_code(status));365366 all_succeeded = all_succeeded && success;367368 if let Some(bar) = progress_bar.as_ref() {
7 unmodified lines
376 bar.finish_and_clear()377 }378379 // Compute statistical quantities374 let t_num = times_real.len();375 let t_mean = mean(&times_real);376 let t_stddev = if times_real.len() > 1 {377 Some(standard_deviation(&times_real, Some(t_mean)))380 let t_num = times_wall_clock.len();381 let t_mean = mean(&times_wall_clock);382 let t_stddev = if times_wall_clock.len() > 1 {383 Some(standard_deviation(&times_wall_clock, Some(t_mean)))384 } else {385 None386 };381 let t_min = min(&times_real);382 let t_max = max(&times_real);387 let t_min = min(&times_wall_clock);388 let t_max = max(&times_wall_clock);389390 let user_mean = measurements.time_user_mean();391 let system_mean = measurements.time_system_mean();392
7 unmodified lines
400 let user_str = user_mean.format(time_unit);401 let system_str = system_mean.format(time_unit);402403 if self.options.output_style != OutputStyleOption::Disabled {398 let mut stdout = io::stdout().lock();399 if measurements.len() == 1 {400 console_writeln!(401 stdout,404 if times_wall_clock.len() == 1 {405 println!(406 " Time ({} ≡): {:>8} {:>8} [User: {}, System: {}]",407 "abs".green().bold(),408 mean_str.green().bold(),409 " ", // alignment
30 unmodified lines
440 let mut warnings = vec![];441442 // Check execution time443 if matches!(self.options.executor_kind, ExecutorKind::Shell(_))440 && measurements441 .wall_clock_times()442 .any(|t| t < MIN_EXECUTION_TIME)444 && times_wall_clock.iter().any(|&t| t < MIN_EXECUTION_TIME)445 {446 warnings.push(Warnings::FastExecutionTime);447 }448
2 unmodified lines
451 warnings.push(Warnings::NonZeroExitCode);452 }453454 // Run outlier detection453 let scores = measurements.modified_zscores();455 let scores = modified_zscores(&times_wall_clock);456457 let outlier_warning_options = OutlierWarningOptions {458 warmup_in_use: self.options.warmup_count > 0,459 prepare_in_use: self
6 unmodified lines
466 };467468 if scores[0] > OUTLIER_THRESHOLD {469 warnings.push(Warnings::SlowInitialRun(468 measurements.wall_clock_times().next().unwrap(),470 times_wall_clock[0],471 outlier_warning_options,472 ));473 } else if scores.iter().any(|&s| s.abs() > OUTLIER_THRESHOLD) {474 warnings.push(Warnings::OutliersDetected(outlier_warning_options));
15 unmodified lines
490 self.run_cleanup_command(self.command.get_parameters().iter().cloned(), output_policy)?;491492 Ok(BenchmarkResult {493 command: self.command.get_name(),492 runs: times_real494 runs: times_wall_clock495 .iter()496 .zip(times_user.iter())497 .zip(times_system.iter())498 .zip(memory_usage_byte.iter())
2 unmodified lines
501 |(502 (((wall_clock_time, user_time), system_time), memory_usage_byte),503 exit_code,504 )| {503 BenchmarkRun {505 Run {506 wall_clock_time: *wall_clock_time,507 user_time: *user_time,508 system_time: *system_time,509 memory_usage_byte: *memory_usage_byte,
22 unmodified lines
modified:src/benchmark/relative_speed.rs+2 added-2 removed
145 unmodified lines
146#[cfg(test)]147fn create_result(name: &str, mean: f64) -> BenchmarkResult {148 use std::collections::BTreeMap;149150 use crate::benchmark::benchmark_result::BenchmarkRun;150 use crate::benchmark::benchmark_result::Run;151152 BenchmarkResult {153 command: name.into(),154 runs: vec![BenchmarkRun {154 runs: vec![Run {155 wall_clock_time: mean,156 user_time: mean,157 system_time: 0.,158 memory_usage_byte: 1024,
70 unmodified lines
modified:src/export/csv.rs+7 added-7 removed
66 unmodified lines
67 }68}6970#[cfg(test)]71use crate::benchmark::benchmark_result::{BenchmarkRun, Parameter};71use crate::benchmark::benchmark_result::{Parameter, Run};7273#[test]74fn test_csv() {75 use crate::benchmark::benchmark_result::Parameter;
8 unmodified lines
84 let results = vec![85 BenchmarkResult {86 command: String::from("command_a"),87 runs: vec![88 BenchmarkRun {88 Run {89 wall_clock_time: 7.0,90 user_time: 7.0,91 system_time: 0.0,92 memory_usage_byte: 1024,93 exit_code: Some(0),94 },95 BenchmarkRun {95 Run {96 wall_clock_time: 8.0,97 user_time: 8.0,98 system_time: 0.0,99 memory_usage_byte: 1024,100 exit_code: Some(0),101 },102 BenchmarkRun {102 Run {103 wall_clock_time: 12.0,104 user_time: 12.0,105 system_time: 0.0,106 memory_usage_byte: 1024,
21 unmodified lines
128 },129 BenchmarkResult {130 command: String::from("command_b"),131 runs: vec![132 BenchmarkRun {132 Run {133 wall_clock_time: 17.0,134 user_time: 17.0,135 system_time: 0.0,136 memory_usage_byte: 1024,137 exit_code: Some(0),138 },139 BenchmarkRun {139 Run {140 wall_clock_time: 18.0,141 user_time: 18.0,142 system_time: 0.0,143 memory_usage_byte: 1024,144 exit_code: Some(0),145 },146 BenchmarkRun {146 Run {147 wall_clock_time: 19.0,148 user_time: 19.0,149 system_time: 0.0,150 memory_usage_byte: 1024,
37 unmodified lines
modified:src/export/tests.rs+25 added-25 removed
1use super::Exporter;2use crate::benchmark::benchmark_result::{BenchmarkResult, BenchmarkRun};2use crate::benchmark::benchmark_result::{BenchmarkResult, Run};3use crate::export::asciidoc::AsciidocExporter;4use crate::export::orgmode::OrgmodeExporter;5use crate::quantity::{byte, second, Information, Time, TimeUnit, Zero};6use crate::{export::markdown::MarkdownExporter, options::SortOrder};
20 unmodified lines
27 let results = [28 BenchmarkResult {29 command: String::from("sleep 0.1"),30 runs: vec![31 BenchmarkRun {31 Run {32 wall_clock_time: 0.09,33 user_time: 0.09,34 system_time: 0.,35 memory_usage_byte: 1024,36 exit_code: Some(0),37 },38 BenchmarkRun {38 Run {39 wall_clock_time: 0.10,40 user_time: 0.10,41 system_time: 0.,42 memory_usage_byte: 1024,43 exit_code: Some(0),44 },45 BenchmarkRun {45 Run {46 wall_clock_time: 0.14,47 user_time: 0.14,48 system_time: 0.,49 memory_usage_byte: 1024,
4 unmodified lines
54 },55 BenchmarkResult {56 command: String::from("sleep 2"),57 runs: vec![58 BenchmarkRun {58 Run {59 wall_clock_time: 2.0,60 user_time: 2.0,61 system_time: 0.,62 memory_usage_byte: 1024,63 exit_code: Some(0),64 },65 BenchmarkRun {65 Run {66 wall_clock_time: 3.0,67 user_time: 3.0,68 system_time: 0.,69 memory_usage_byte: 1024,70 exit_code: Some(0),71 },72 BenchmarkRun {72 Run {73 wall_clock_time: 4.0,74 user_time: 4.0,75 system_time: 0.,76 memory_usage_byte: 1024,
49 unmodified lines
126 let results = [127 BenchmarkResult {128 command: String::from("sleep 2"),129 runs: vec![130 BenchmarkRun {130 Run {131 wall_clock_time: 2.1,132 user_time: 2.1,133 system_time: 0.,134 memory_usage_byte: 1024,135 exit_code: Some(0),136 },137 BenchmarkRun {137 Run {138 wall_clock_time: 2.2,139 user_time: 2.2,140 system_time: 0.,141 memory_usage_byte: 1024,142 exit_code: Some(0),143 },144 BenchmarkRun {144 Run {145 wall_clock_time: 2.3,146 user_time: 2.3,147 system_time: 0.,148 memory_usage_byte: 1024,
4 unmodified lines
153 },154 BenchmarkResult {155 command: String::from("sleep 0.1"),156 runs: vec![157 BenchmarkRun {157 Run {158 wall_clock_time: 0.1,159 user_time: 0.1,160 system_time: 0.,161 memory_usage_byte: 1024,162 exit_code: Some(0),163 },164 BenchmarkRun {164 Run {165 wall_clock_time: 0.2,166 user_time: 0.2,167 system_time: 0.,168 memory_usage_byte: 1024,169 exit_code: Some(0),170 },171 BenchmarkRun {171 Run {172 wall_clock_time: 0.3,173 user_time: 0.3,174 system_time: 0.,175 memory_usage_byte: 1024,
49 unmodified lines
225 let timing_results = [226 BenchmarkResult {227 command: String::from("sleep 2"),228 runs: vec![229 BenchmarkRun {229 Run {230 wall_clock_time: 2.1,231 user_time: 2.1,232 system_time: 0.,233 memory_usage_byte: 1024,234 exit_code: Some(0),235 },236 BenchmarkRun {236 Run {237 wall_clock_time: 2.2,238 user_time: 2.2,239 system_time: 0.,240 memory_usage_byte: 1024,241 exit_code: Some(0),242 },243 BenchmarkRun {243 Run {244 wall_clock_time: 2.3,245 user_time: 2.3,246 system_time: 0.,247 memory_usage_byte: 1024,
4 unmodified lines
252 },253 BenchmarkResult {254 command: String::from("sleep 0.1"),255 runs: vec![256 BenchmarkRun {256 Run {257 wall_clock_time: 0.1,258 user_time: 0.1,259 system_time: 0.,260 memory_usage_byte: 1024,261 exit_code: Some(0),262 },263 BenchmarkRun {263 Run {264 wall_clock_time: 0.2,265 user_time: 0.2,266 system_time: 0.,267 memory_usage_byte: 1024,268 exit_code: Some(0),269 },270 BenchmarkRun {270 Run {271 wall_clock_time: 0.3,272 user_time: 0.3,273 system_time: 0.,274 memory_usage_byte: 1024,
48 unmodified lines
323 let results = [324 BenchmarkResult {325 command: String::from("sleep 2"),326 runs: vec![327 BenchmarkRun {327 Run {328 wall_clock_time: 2.01,329 user_time: 2.01,330 system_time: 0.,331 memory_usage_byte: 1024,332 exit_code: Some(0),333 },334 BenchmarkRun {334 Run {335 wall_clock_time: 2.02,336 user_time: 2.02,337 system_time: 0.,338 memory_usage_byte: 1024,339 exit_code: Some(0),340 },341 BenchmarkRun {341 Run {342 wall_clock_time: 2.03,343 user_time: 2.03,344 system_time: 0.,345 memory_usage_byte: 1024,
4 unmodified lines
350 },351 BenchmarkResult {352 command: String::from("sleep 0.1"),353 runs: vec![354 BenchmarkRun {354 Run {355 wall_clock_time: 0.11,356 user_time: 0.11,357 system_time: 0.,358 memory_usage_byte: 1024,359 exit_code: Some(0),360 },361 BenchmarkRun {361 Run {362 wall_clock_time: 0.12,363 user_time: 0.12,364 system_time: 0.,365 memory_usage_byte: 1024,366 exit_code: Some(0),367 },368 BenchmarkRun {368 Run {369 wall_clock_time: 0.13,370 user_time: 0.13,371 system_time: 0.,372 memory_usage_byte: 1024,
44 unmodified lines
modified:src/timer/mod.rs+3 added-3 removed
25 unmodified lines
2627/// Used to indicate the result of running a command28#[derive(Debug, Copy, Clone)]29pub struct TimerResult {30 pub time_real: Second,30 pub time_wall_clock: Second,31 pub time_user: Second,32 pub time_system: Second,33 pub memory_usage_byte: u64,34 /// The exit status of the process
58 unmodified lines
93 discard(output);94 }9596 let (status, time_user, time_system, memory_usage_byte) = cpu_timer.stop(child)?;97 let time_real = wallclock_timer.stop();97 let time_wall_clock = wallclock_timer.stop();9899 Ok(Measurement {99 Ok(TimerResult {100 time_wall_clock,101 time_user,102 time_system,103 peak_memory_usage,
3 unmodified lines