mirror of
https://github.com/sharkdp/hyperfine.git
synced 2026-11-01 08:50:19 +00:00
Proper shell overhead computation
This commit is contained in:
1 parent
6f51232a8a
commit
6887835f34
5 files changed
+40
-22
No files matched your search
@@ -165,12 +165,12 @@ impl<'a> Executor for ShellExecutor<'a> {
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct MockExecutor<'a> {
|
||||
shell: &'a Shell,
|
||||
pub struct MockExecutor {
|
||||
shell: Option<String>,
|
||||
}
|
||||
|
||||
impl<'a> MockExecutor<'a> {
|
||||
pub fn new(shell: &'a Shell) -> Self {
|
||||
impl MockExecutor {
|
||||
pub fn new(shell: Option<String>) -> Self {
|
||||
MockExecutor { shell }
|
||||
}
|
||||
|
||||
@@ -184,7 +184,7 @@ impl<'a> MockExecutor<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Executor for MockExecutor<'a> {
|
||||
impl Executor for MockExecutor {
|
||||
fn time_command(
|
||||
&self,
|
||||
command: &Command<'_>,
|
||||
@@ -217,9 +217,9 @@ impl<'a> Executor for MockExecutor<'a> {
|
||||
}
|
||||
|
||||
fn time_overhead(&self) -> Second {
|
||||
match self.shell {
|
||||
Shell::Default(_) => 0.0,
|
||||
Shell::Custom(shell) => Self::extract_time(&shell[0]),
|
||||
match &self.shell {
|
||||
None => 0.0,
|
||||
Some(shell) => Self::extract_time(shell),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -141,11 +141,10 @@ impl<'a> Benchmark<'a> {
|
||||
)
|
||||
});
|
||||
let run_preparation_command = || {
|
||||
if let Some(ref cmd) = preparation_command {
|
||||
self.run_preparation_command(cmd)
|
||||
} else {
|
||||
Ok(TimingResult::default())
|
||||
}
|
||||
preparation_command
|
||||
.as_ref()
|
||||
.map(|cmd| self.run_preparation_command(cmd))
|
||||
.transpose()
|
||||
};
|
||||
|
||||
self.run_setup_command(self.command.get_parameters().iter().cloned())?;
|
||||
@@ -186,6 +185,8 @@ impl<'a> Benchmark<'a> {
|
||||
};
|
||||
|
||||
let preparation_result = run_preparation_command()?;
|
||||
let preparation_overhead =
|
||||
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)?;
|
||||
@@ -193,7 +194,7 @@ impl<'a> Benchmark<'a> {
|
||||
|
||||
// Determine number of benchmark runs
|
||||
let runs_in_min_time = (self.options.min_benchmarking_time
|
||||
/ (res.time_real + preparation_result.time_real + self.executor.time_overhead()))
|
||||
/ (res.time_real + self.executor.time_overhead() + preparation_overhead))
|
||||
as u64;
|
||||
|
||||
let count = {
|
||||
|
||||
@@ -33,7 +33,7 @@ impl<'a> Scheduler<'a> {
|
||||
|
||||
pub fn run_benchmarks(&mut self) -> Result<()> {
|
||||
let mut executor: Box<dyn Executor> = match self.options.executor_kind {
|
||||
ExecutorKind::Mock(ref shell) => Box::new(MockExecutor::new(shell)),
|
||||
ExecutorKind::Mock(ref shell) => Box::new(MockExecutor::new(shell.clone())),
|
||||
ExecutorKind::Shell(ref shell) => Box::new(ShellExecutor::new(shell, &self.options)),
|
||||
};
|
||||
|
||||
|
||||
+3
-3
@@ -126,7 +126,7 @@ impl Default for CommandOutputPolicy {
|
||||
|
||||
pub enum ExecutorKind {
|
||||
Shell(Shell),
|
||||
Mock(Shell),
|
||||
Mock(Option<String>),
|
||||
}
|
||||
|
||||
impl Default for ExecutorKind {
|
||||
@@ -276,8 +276,8 @@ impl Options {
|
||||
{
|
||||
(false, Some(shell)) => ExecutorKind::Shell(Shell::from_str(shell)?),
|
||||
(false, None) => ExecutorKind::Shell(Shell::default()),
|
||||
(true, Some(shell)) => ExecutorKind::Mock(Shell::from_str(shell)?),
|
||||
(true, None) => ExecutorKind::Mock(Shell::default()),
|
||||
(true, Some(shell)) => ExecutorKind::Mock(Some(shell.into())),
|
||||
(true, None) => ExecutorKind::Mock(None),
|
||||
};
|
||||
|
||||
if matches.is_present("ignore-failure") {
|
||||
|
||||
Reference in new issue
Block a user