mirror of
https://github.com/sharkdp/hyperfine.git
synced 2024-11-22 11:43:03 +03:00
Rename to run_command_and_measure
This commit is contained in:
parent
826449bc8f
commit
7c929f7e48
@ -13,14 +13,23 @@ use anyhow::{bail, Result};
|
||||
use statistical::mean;
|
||||
|
||||
pub trait Executor {
|
||||
fn time_command(
|
||||
/// Run the given command and measure the execution time
|
||||
fn run_command_and_measure(
|
||||
&self,
|
||||
command: &Command<'_>,
|
||||
command_failure_action: Option<CmdFailureAction>,
|
||||
) -> Result<(TimingResult, ExitStatus)>;
|
||||
|
||||
/// Perform a calibration of this executor. For example,
|
||||
/// when running commands through a shell, we need to
|
||||
/// measure the shell spawning time separately in order
|
||||
/// to subtract it from the full runtime later.
|
||||
fn calibrate(&mut self) -> Result<()>;
|
||||
|
||||
/// Return the time overhead for this executor when
|
||||
/// performing a measurement. This should return the time
|
||||
/// that is being used in addition to the actual runtime
|
||||
/// of the command.
|
||||
fn time_overhead(&self) -> Second;
|
||||
}
|
||||
|
||||
@ -49,8 +58,7 @@ impl<'a> ShellExecutor<'a> {
|
||||
}
|
||||
|
||||
impl<'a> Executor for ShellExecutor<'a> {
|
||||
/// Run the given shell command and measure the execution time
|
||||
fn time_command(
|
||||
fn run_command_and_measure(
|
||||
&self,
|
||||
command: &Command<'_>,
|
||||
command_failure_action: Option<CmdFailureAction>,
|
||||
@ -117,7 +125,7 @@ impl<'a> Executor for ShellExecutor<'a> {
|
||||
|
||||
for _ in 0..COUNT {
|
||||
// Just run the shell without any command
|
||||
let res = self.time_command(&Command::new(None, ""), None);
|
||||
let res = self.run_command_and_measure(&Command::new(None, ""), None);
|
||||
|
||||
match res {
|
||||
Err(_) => {
|
||||
@ -183,7 +191,7 @@ impl MockExecutor {
|
||||
}
|
||||
|
||||
impl Executor for MockExecutor {
|
||||
fn time_command(
|
||||
fn run_command_and_measure(
|
||||
&self,
|
||||
command: &Command<'_>,
|
||||
_command_failure_action: Option<CmdFailureAction>,
|
||||
|
@ -57,7 +57,7 @@ impl<'a> Benchmark<'a> {
|
||||
error_output: &'static str,
|
||||
) -> Result<TimingResult> {
|
||||
self.executor
|
||||
.time_command(command, Some(CmdFailureAction::RaiseError))
|
||||
.run_command_and_measure(command, Some(CmdFailureAction::RaiseError))
|
||||
.map(|r| r.0)
|
||||
.map_err(|_| anyhow!(error_output))
|
||||
}
|
||||
@ -163,7 +163,7 @@ impl<'a> Benchmark<'a> {
|
||||
|
||||
for _ in 0..self.options.warmup_count {
|
||||
let _ = run_preparation_command()?;
|
||||
let _ = self.executor.time_command(self.command, None)?;
|
||||
let _ = self.executor.run_command_and_measure(self.command, None)?;
|
||||
if let Some(bar) = progress_bar.as_ref() {
|
||||
bar.inc(1)
|
||||
}
|
||||
@ -189,7 +189,7 @@ impl<'a> Benchmark<'a> {
|
||||
preparation_result.map_or(0.0, |res| res.time_real + self.executor.time_overhead());
|
||||
|
||||
// Initial timing run
|
||||
let (res, status) = self.executor.time_command(self.command, None)?;
|
||||
let (res, status) = self.executor.run_command_and_measure(self.command, None)?;
|
||||
let success = status.success();
|
||||
|
||||
// Determine number of benchmark runs
|
||||
@ -239,7 +239,7 @@ impl<'a> Benchmark<'a> {
|
||||
bar.set_message(msg.to_owned())
|
||||
}
|
||||
|
||||
let (res, status) = self.executor.time_command(self.command, None)?;
|
||||
let (res, status) = self.executor.run_command_and_measure(self.command, None)?;
|
||||
let success = status.success();
|
||||
|
||||
times_real.push(res.time_real);
|
||||
|
Loading…
Reference in New Issue
Block a user