Skip to content
Myr

Further simplify execute_and_measure

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 0ffc6d7 · Browse files · 2 files+8 added−10 removed
This commit

State

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

Diff stats

2 files+8 added−10 removed

  • other:+8 added−10 removed

2 files+8 added−10 removed

modified:src/benchmark/executor.rs+3 added-3 removed
7 unmodified lines
8use crate::util::units::Second;910use super::timing_result::TimingResult;1112use anyhow::{bail, Result};12use anyhow::{bail, Context, Result};13use statistical::mean;1415pub trait Executor {16 /// Run the given command and measure the execution time
61 unmodified lines
78 )79 .stdin(Stdio::null())80 .stdout(stdout)81 .stderr(stderr);82 let error_message = format!("Failed to run command '{}'", command.get_command_line());8283 let wallclock_timer = WallClockTimer::start();85 let result = execute_and_measure(command_builder, &error_message)?;84 let result = execute_and_measure(command_builder)85 .with_context(|| format!("Failed to run command '{}'", command.get_command_line()))?;86 let mut time_real = wallclock_timer.stop();8788 let mut time_user = result.user_time;89 let mut time_system = result.system_time;
160 unmodified lines
modified:src/timer/mod.rs+5 added-7 removed
8 unmodified lines
9use crate::util::units::Second;1011use std::process::{Command, ExitStatus};1213use anyhow::{Context, Result};13use anyhow::Result;1415#[derive(Debug, Copy, Clone)]16struct CPUTimes {17 /// Total amount of time spent executing in user mode
17 unmodified lines
35}3637/// Execute the given command and return a timing summary38#[cfg(not(windows))]39pub fn execute_and_measure(mut command: Command, error_message: &str) -> Result<ExecuteResult> {39pub fn execute_and_measure(mut command: Command) -> Result<ExecuteResult> {40 let cpu_timer = self::unix_timer::CPUTimer::start();41 let status = command42 .status()43 .with_context(|| error_message.to_string())?;41 let status = command.status()?;42 let (user_time, system_time) = cpu_timer.stop();4344 Ok(ExecuteResult {45 user_time,
3 unmodified lines
49}5051/// Execute the given command and return a timing summary52#[cfg(windows)]55pub fn execute_and_measure(mut command: Command, error_message: &str) -> Result<ExecuteResult> {56 let mut child = command.spawn().with_context(|| error_message.to_string())?;53pub fn execute_and_measure(mut command: Command) -> Result<ExecuteResult> {54 let mut child = command.spawn()?;55 let cpu_timer = self::windows_timer::CPUTimer::start_for_process(&child);56 let status = child.wait()?;5758 let (user_time, system_time) = cpu_timer.stop();
6 unmodified lines