2022-02-20 13:44:34 +01:00
|
|
|
|
pub mod benchmark_result;
|
2022-02-22 08:36:56 +01:00
|
|
|
|
pub mod executor;
|
2026-10-05 09:47:09 +02:00
|
|
|
|
pub mod measurement;
|
2022-02-06 19:54:59 +01:00
|
|
|
|
pub mod relative_speed;
|
2022-02-07 21:03:23 +01:00
|
|
|
|
pub mod scheduler;
|
2022-02-06 19:37:15 +01:00
|
|
|
|
|
2022-02-21 08:46:10 +01:00
|
|
|
|
use std::cmp;
|
2026-10-02 17:18:56 +08:00
|
|
|
|
use std::io::{self, Write};
|
2022-02-21 08:46:10 +01:00
|
|
|
|
|
2024-11-10 22:21:22 +01:00
|
|
|
|
use crate::benchmark::executor::BenchmarkIteration;
|
2022-02-21 08:46:10 +01:00
|
|
|
|
use crate::command::Command;
|
2024-11-11 22:18:19 +01:00
|
|
|
|
use crate::options::{
|
|
|
|
|
|
CmdFailureAction, CommandOutputPolicy, ExecutorKind, Options, OutputStyleOption,
|
|
|
|
|
|
};
|
2026-10-05 10:10:09 +02:00
|
|
|
|
use crate::outlier_detection::OUTLIER_THRESHOLD;
|
2026-10-02 17:18:56 +08:00
|
|
|
|
use crate::output::console_writeln;
|
2022-10-30 20:55:12 -07:00
|
|
|
|
use crate::output::progress_bar::{
|
|
|
|
|
|
get_progress_bar, replace_message_template, reset_progress_template,
|
|
|
|
|
|
};
|
2022-11-20 21:18:03 +01:00
|
|
|
|
use crate::output::warnings::{OutlierWarningOptions, Warnings};
|
2022-02-21 08:46:10 +01:00
|
|
|
|
use crate::parameter::ParameterNameAndValue;
|
2026-10-05 12:46:10 +02:00
|
|
|
|
use crate::quantity::{const_time_from_seconds, ratio, FormatQuantity, Time, Zero};
|
2026-10-05 12:35:24 +02:00
|
|
|
|
use benchmark_result::{BenchmarkResult, Parameter};
|
2026-10-05 10:10:09 +02:00
|
|
|
|
use measurement::{Measurement, Measurements};
|
2022-02-21 08:46:10 +01:00
|
|
|
|
|
2022-02-22 08:36:56 +01:00
|
|
|
|
use anyhow::{anyhow, Result};
|
2022-02-21 08:46:10 +01:00
|
|
|
|
use colored::*;
|
2018-01-31 17:51:07 -05:00
|
|
|
|
|
2022-02-22 08:36:56 +01:00
|
|
|
|
use self::executor::Executor;
|
|
|
|
|
|
|
2021-08-24 22:16:40 +02:00
|
|
|
|
/// Threshold for warning about fast execution time
|
2026-10-05 10:32:32 +02:00
|
|
|
|
pub const MIN_EXECUTION_TIME: Time = const_time_from_seconds(5e-3);
|
2022-02-21 08:46:10 +01:00
|
|
|
|
|
|
|
|
|
|
pub struct Benchmark<'a> {
|
|
|
|
|
|
number: usize,
|
|
|
|
|
|
command: &'a Command<'a>,
|
|
|
|
|
|
options: &'a Options,
|
2022-02-22 08:36:56 +01:00
|
|
|
|
executor: &'a dyn Executor,
|
2022-02-21 08:46:10 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
impl<'a> Benchmark<'a> {
|
|
|
|
|
|
pub fn new(
|
|
|
|
|
|
number: usize,
|
|
|
|
|
|
command: &'a Command<'a>,
|
|
|
|
|
|
options: &'a Options,
|
2022-02-22 08:36:56 +01:00
|
|
|
|
executor: &'a dyn Executor,
|
2022-02-21 08:46:10 +01:00
|
|
|
|
) -> Self {
|
|
|
|
|
|
Benchmark {
|
|
|
|
|
|
number,
|
|
|
|
|
|
command,
|
|
|
|
|
|
options,
|
2022-02-22 08:36:56 +01:00
|
|
|
|
executor,
|
2022-02-21 08:46:10 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// Run setup, cleanup, or preparation commands
|
|
|
|
|
|
fn run_intermediate_command(
|
|
|
|
|
|
&self,
|
|
|
|
|
|
command: &Command<'_>,
|
|
|
|
|
|
error_output: &'static str,
|
2024-11-11 22:18:19 +01:00
|
|
|
|
output_policy: &CommandOutputPolicy,
|
2026-10-05 12:40:33 +02:00
|
|
|
|
iteration: executor::BenchmarkIteration,
|
2026-10-05 09:47:09 +02:00
|
|
|
|
) -> Result<Measurement> {
|
2022-02-22 08:36:56 +01:00
|
|
|
|
self.executor
|
2024-11-10 22:21:22 +01:00
|
|
|
|
.run_command_and_measure(
|
|
|
|
|
|
command,
|
2025-03-13 08:45:56 +00:00
|
|
|
|
iteration,
|
2024-11-10 22:21:22 +01:00
|
|
|
|
Some(CmdFailureAction::RaiseError),
|
2024-11-11 22:18:19 +01:00
|
|
|
|
output_policy,
|
2024-11-10 22:21:22 +01:00
|
|
|
|
)
|
2022-02-22 08:36:56 +01:00
|
|
|
|
.map_err(|_| anyhow!(error_output))
|
2022-02-21 08:46:10 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// Run the command specified by `--setup`.
|
|
|
|
|
|
fn run_setup_command(
|
|
|
|
|
|
&self,
|
|
|
|
|
|
parameters: impl IntoIterator<Item = ParameterNameAndValue<'a>>,
|
2024-11-11 22:18:19 +01:00
|
|
|
|
output_policy: &CommandOutputPolicy,
|
2026-10-05 09:47:09 +02:00
|
|
|
|
) -> Result<Measurement> {
|
2022-02-21 08:46:10 +01:00
|
|
|
|
let command = self
|
|
|
|
|
|
.options
|
|
|
|
|
|
.setup_command
|
|
|
|
|
|
.as_ref()
|
|
|
|
|
|
.map(|setup_command| Command::new_parametrized(None, setup_command, parameters));
|
|
|
|
|
|
|
|
|
|
|
|
let error_output = "The setup command terminated with a non-zero exit code. \
|
|
|
|
|
|
Append ' || true' to the command if you are sure that this can be ignored.";
|
|
|
|
|
|
|
|
|
|
|
|
Ok(command
|
2026-10-05 12:40:33 +02:00
|
|
|
|
.map(|cmd| {
|
|
|
|
|
|
self.run_intermediate_command(
|
|
|
|
|
|
&cmd,
|
|
|
|
|
|
error_output,
|
|
|
|
|
|
output_policy,
|
|
|
|
|
|
BenchmarkIteration::NonBenchmarkRun,
|
|
|
|
|
|
)
|
|
|
|
|
|
})
|
2022-02-21 08:46:10 +01:00
|
|
|
|
.transpose()?
|
|
|
|
|
|
.unwrap_or_default())
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// Run the command specified by `--cleanup`.
|
|
|
|
|
|
fn run_cleanup_command(
|
|
|
|
|
|
&self,
|
|
|
|
|
|
parameters: impl IntoIterator<Item = ParameterNameAndValue<'a>>,
|
2024-11-11 22:18:19 +01:00
|
|
|
|
output_policy: &CommandOutputPolicy,
|
2026-10-05 09:47:09 +02:00
|
|
|
|
) -> Result<Measurement> {
|
2022-02-21 08:46:10 +01:00
|
|
|
|
let command = self
|
|
|
|
|
|
.options
|
|
|
|
|
|
.cleanup_command
|
|
|
|
|
|
.as_ref()
|
|
|
|
|
|
.map(|cleanup_command| Command::new_parametrized(None, cleanup_command, parameters));
|
|
|
|
|
|
|
|
|
|
|
|
let error_output = "The cleanup command terminated with a non-zero exit code. \
|
|
|
|
|
|
Append ' || true' to the command if you are sure that this can be ignored.";
|
|
|
|
|
|
|
|
|
|
|
|
Ok(command
|
2026-10-05 12:40:33 +02:00
|
|
|
|
.map(|cmd| {
|
|
|
|
|
|
self.run_intermediate_command(
|
|
|
|
|
|
&cmd,
|
|
|
|
|
|
error_output,
|
|
|
|
|
|
output_policy,
|
|
|
|
|
|
BenchmarkIteration::NonBenchmarkRun,
|
|
|
|
|
|
)
|
|
|
|
|
|
})
|
2022-02-21 08:46:10 +01:00
|
|
|
|
.transpose()?
|
|
|
|
|
|
.unwrap_or_default())
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// Run the command specified by `--prepare`.
|
2024-11-11 22:18:19 +01:00
|
|
|
|
fn run_preparation_command(
|
|
|
|
|
|
&self,
|
|
|
|
|
|
command: &Command<'_>,
|
|
|
|
|
|
output_policy: &CommandOutputPolicy,
|
2026-10-05 12:40:33 +02:00
|
|
|
|
iteration: executor::BenchmarkIteration,
|
2026-10-05 09:47:09 +02:00
|
|
|
|
) -> Result<Measurement> {
|
2022-02-21 08:46:10 +01:00
|
|
|
|
let error_output = "The preparation command terminated with a non-zero exit code. \
|
|
|
|
|
|
Append ' || true' to the command if you are sure that this can be ignored.";
|
|
|
|
|
|
|
2025-03-13 08:45:56 +00:00
|
|
|
|
self.run_intermediate_command(command, error_output, output_policy, iteration)
|
2022-02-21 08:46:10 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-01-21 19:27:08 +00:00
|
|
|
|
/// Run the command specified by `--conclude`.
|
2024-11-11 22:18:19 +01:00
|
|
|
|
fn run_conclusion_command(
|
|
|
|
|
|
&self,
|
|
|
|
|
|
command: &Command<'_>,
|
|
|
|
|
|
output_policy: &CommandOutputPolicy,
|
2025-03-13 08:45:56 +00:00
|
|
|
|
iteration: executor::BenchmarkIteration,
|
2026-10-05 09:47:09 +02:00
|
|
|
|
) -> Result<Measurement> {
|
2024-01-21 19:27:08 +00:00
|
|
|
|
let error_output = "The conclusion command terminated with a non-zero exit code. \
|
|
|
|
|
|
Append ' || true' to the command if you are sure that this can be ignored.";
|
|
|
|
|
|
|
2026-10-05 12:40:33 +02:00
|
|
|
|
self.run_intermediate_command(command, error_output, output_policy, iteration)
|
2024-01-21 19:27:08 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2022-02-21 08:46:10 +01:00
|
|
|
|
/// Run the benchmark for a single command
|
|
|
|
|
|
pub fn run(&self) -> Result<BenchmarkResult> {
|
|
|
|
|
|
if self.options.output_style != OutputStyleOption::Disabled {
|
2026-10-02 17:18:56 +08:00
|
|
|
|
console_writeln!(
|
|
|
|
|
|
io::stdout(),
|
2022-02-21 08:46:10 +01:00
|
|
|
|
"{}{}: {}",
|
|
|
|
|
|
"Benchmark ".bold(),
|
|
|
|
|
|
(self.number + 1).to_string().bold(),
|
2023-04-20 21:32:06 +02:00
|
|
|
|
self.command.get_name_with_unused_parameters(),
|
2026-10-02 17:18:56 +08:00
|
|
|
|
)?;
|
2022-02-21 08:46:10 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-10-05 10:10:09 +02:00
|
|
|
|
let mut measurements = Measurements::default();
|
2022-02-21 08:46:10 +01:00
|
|
|
|
let mut all_succeeded = true;
|
|
|
|
|
|
|
2024-11-11 22:18:19 +01:00
|
|
|
|
let output_policy = &self.options.command_output_policies[self.number];
|
|
|
|
|
|
|
2022-02-21 08:46:10 +01:00
|
|
|
|
let preparation_command = self.options.preparation_command.as_ref().map(|values| {
|
|
|
|
|
|
let preparation_command = if values.len() == 1 {
|
|
|
|
|
|
&values[0]
|
|
|
|
|
|
} else {
|
|
|
|
|
|
&values[self.number]
|
|
|
|
|
|
};
|
|
|
|
|
|
Command::new_parametrized(
|
|
|
|
|
|
None,
|
|
|
|
|
|
preparation_command,
|
|
|
|
|
|
self.command.get_parameters().iter().cloned(),
|
|
|
|
|
|
)
|
|
|
|
|
|
});
|
2024-11-11 22:18:19 +01:00
|
|
|
|
|
2026-10-05 12:40:33 +02:00
|
|
|
|
let run_preparation_command = |iteration: executor::BenchmarkIteration| {
|
2022-02-22 08:58:57 +01:00
|
|
|
|
preparation_command
|
|
|
|
|
|
.as_ref()
|
2025-03-13 08:45:56 +00:00
|
|
|
|
.map(|cmd| self.run_preparation_command(cmd, output_policy, iteration))
|
2022-02-22 08:58:57 +01:00
|
|
|
|
.transpose()
|
2022-02-21 08:46:10 +01:00
|
|
|
|
};
|
|
|
|
|
|
|
2024-01-21 19:27:08 +00:00
|
|
|
|
let conclusion_command = self.options.conclusion_command.as_ref().map(|values| {
|
|
|
|
|
|
let conclusion_command = if values.len() == 1 {
|
|
|
|
|
|
&values[0]
|
|
|
|
|
|
} else {
|
|
|
|
|
|
&values[self.number]
|
|
|
|
|
|
};
|
|
|
|
|
|
Command::new_parametrized(
|
|
|
|
|
|
None,
|
|
|
|
|
|
conclusion_command,
|
|
|
|
|
|
self.command.get_parameters().iter().cloned(),
|
|
|
|
|
|
)
|
|
|
|
|
|
});
|
2025-03-13 08:45:56 +00:00
|
|
|
|
let run_conclusion_command = |iteration: executor::BenchmarkIteration| {
|
2024-01-21 19:27:08 +00:00
|
|
|
|
conclusion_command
|
|
|
|
|
|
.as_ref()
|
2025-03-13 08:45:56 +00:00
|
|
|
|
.map(|cmd| self.run_conclusion_command(cmd, output_policy, iteration))
|
2024-01-21 19:27:08 +00:00
|
|
|
|
.transpose()
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2024-11-11 22:18:19 +01:00
|
|
|
|
self.run_setup_command(self.command.get_parameters().iter().cloned(), output_policy)?;
|
2022-02-21 08:46:10 +01:00
|
|
|
|
|
|
|
|
|
|
// Warmup phase
|
|
|
|
|
|
if self.options.warmup_count > 0 {
|
|
|
|
|
|
let progress_bar = if self.options.output_style != OutputStyleOption::Disabled {
|
|
|
|
|
|
Some(get_progress_bar(
|
|
|
|
|
|
self.options.warmup_count,
|
|
|
|
|
|
"Performing warmup runs",
|
|
|
|
|
|
self.options.output_style,
|
|
|
|
|
|
))
|
|
|
|
|
|
} else {
|
|
|
|
|
|
None
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2024-11-10 22:21:22 +01:00
|
|
|
|
for i in 0..self.options.warmup_count {
|
2025-03-13 08:45:56 +00:00
|
|
|
|
let warmup_iteration = BenchmarkIteration::Warmup(i);
|
2026-10-05 12:40:33 +02:00
|
|
|
|
let _ = run_preparation_command(warmup_iteration)?;
|
2024-11-10 22:21:22 +01:00
|
|
|
|
let _ = self.executor.run_command_and_measure(
|
|
|
|
|
|
self.command,
|
2026-10-05 12:40:33 +02:00
|
|
|
|
warmup_iteration,
|
2024-11-10 22:21:22 +01:00
|
|
|
|
None,
|
2024-11-11 22:18:19 +01:00
|
|
|
|
output_policy,
|
2024-11-10 22:21:22 +01:00
|
|
|
|
)?;
|
2025-03-13 08:45:56 +00:00
|
|
|
|
let _ = run_conclusion_command(warmup_iteration)?;
|
2022-02-21 08:46:10 +01:00
|
|
|
|
if let Some(bar) = progress_bar.as_ref() {
|
|
|
|
|
|
bar.inc(1)
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
if let Some(bar) = progress_bar.as_ref() {
|
|
|
|
|
|
bar.finish_and_clear()
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Set up progress bar (and spinner for initial measurement)
|
|
|
|
|
|
let progress_bar = if self.options.output_style != OutputStyleOption::Disabled {
|
2022-10-30 20:55:12 -07:00
|
|
|
|
let temp_bar = get_progress_bar(
|
2022-02-21 08:46:10 +01:00
|
|
|
|
self.options.run_bounds.min,
|
2022-10-30 20:55:12 -07:00
|
|
|
|
"Initial time measurement:",
|
2022-02-21 08:46:10 +01:00
|
|
|
|
self.options.output_style,
|
2022-10-30 20:55:12 -07:00
|
|
|
|
);
|
|
|
|
|
|
let template = format!("{{msg}} {{elapsed:<{}}}", 30 - temp_bar.message().len() - 1,);
|
|
|
|
|
|
Some(replace_message_template(temp_bar, &template))
|
2022-02-21 08:46:10 +01:00
|
|
|
|
} else {
|
|
|
|
|
|
None
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2025-03-13 08:45:56 +00:00
|
|
|
|
let benchmark_iteration = BenchmarkIteration::Benchmark(0);
|
2026-10-05 12:40:33 +02:00
|
|
|
|
let preparation_result = run_preparation_command(benchmark_iteration)?;
|
2026-10-05 10:32:32 +02:00
|
|
|
|
let preparation_overhead = preparation_result.map_or(Time::zero(), |res| {
|
2026-10-05 10:09:41 +02:00
|
|
|
|
res.time_wall_clock + self.executor.time_overhead()
|
|
|
|
|
|
});
|
2022-02-21 08:46:10 +01:00
|
|
|
|
|
|
|
|
|
|
// Initial timing run
|
2026-10-05 09:47:09 +02:00
|
|
|
|
let res = self.executor.run_command_and_measure(
|
2024-11-10 22:21:22 +01:00
|
|
|
|
self.command,
|
2026-10-05 12:40:33 +02:00
|
|
|
|
benchmark_iteration,
|
2024-11-10 22:21:22 +01:00
|
|
|
|
None,
|
2024-11-11 22:18:19 +01:00
|
|
|
|
output_policy,
|
2024-11-10 22:21:22 +01:00
|
|
|
|
)?;
|
2026-10-05 10:09:41 +02:00
|
|
|
|
let success = res.exit_status.success();
|
2022-02-21 08:46:10 +01:00
|
|
|
|
|
2025-03-13 08:45:56 +00:00
|
|
|
|
let conclusion_result = run_conclusion_command(benchmark_iteration)?;
|
2026-10-05 10:32:32 +02:00
|
|
|
|
let conclusion_overhead = conclusion_result.map_or(Time::zero(), |res| {
|
2026-10-05 10:09:41 +02:00
|
|
|
|
res.time_wall_clock + self.executor.time_overhead()
|
|
|
|
|
|
});
|
2024-01-21 19:27:08 +00:00
|
|
|
|
|
2022-02-21 08:46:10 +01:00
|
|
|
|
// Determine number of benchmark runs
|
|
|
|
|
|
let runs_in_min_time = (self.options.min_benchmarking_time
|
2026-10-05 10:09:41 +02:00
|
|
|
|
/ (res.time_wall_clock
|
2024-01-21 19:27:08 +00:00
|
|
|
|
+ self.executor.time_overhead()
|
|
|
|
|
|
+ preparation_overhead
|
2026-10-05 10:32:32 +02:00
|
|
|
|
+ conclusion_overhead))
|
|
|
|
|
|
.get::<ratio>() as u64;
|
2022-02-21 08:46:10 +01:00
|
|
|
|
|
|
|
|
|
|
let count = {
|
|
|
|
|
|
let min = cmp::max(runs_in_min_time, self.options.run_bounds.min);
|
|
|
|
|
|
|
|
|
|
|
|
self.options
|
|
|
|
|
|
.run_bounds
|
|
|
|
|
|
.max
|
|
|
|
|
|
.as_ref()
|
|
|
|
|
|
.map(|max| cmp::min(min, *max))
|
|
|
|
|
|
.unwrap_or(min)
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
let count_remaining = count - 1;
|
|
|
|
|
|
|
|
|
|
|
|
// Save the first result
|
2026-10-05 10:10:09 +02:00
|
|
|
|
measurements.push(res);
|
2022-02-21 08:46:10 +01:00
|
|
|
|
|
|
|
|
|
|
all_succeeded = all_succeeded && success;
|
|
|
|
|
|
|
|
|
|
|
|
// Re-configure the progress bar
|
2022-10-30 20:55:12 -07:00
|
|
|
|
let progress_bar = progress_bar.map(reset_progress_template);
|
2022-02-21 08:46:10 +01:00
|
|
|
|
if let Some(bar) = progress_bar.as_ref() {
|
|
|
|
|
|
bar.set_length(count)
|
|
|
|
|
|
}
|
|
|
|
|
|
if let Some(bar) = progress_bar.as_ref() {
|
|
|
|
|
|
bar.inc(1)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Gather statistics (perform the actual benchmark)
|
2024-11-10 22:21:22 +01:00
|
|
|
|
for i in 0..count_remaining {
|
2025-03-13 08:45:56 +00:00
|
|
|
|
let benchmark_iteration = BenchmarkIteration::Benchmark(i + 1);
|
2026-10-05 12:40:33 +02:00
|
|
|
|
run_preparation_command(benchmark_iteration)?;
|
2022-02-21 08:46:10 +01:00
|
|
|
|
|
|
|
|
|
|
let msg = {
|
2026-10-05 11:46:49 +02:00
|
|
|
|
let t_wall_clock_mean = measurements.time_wall_clock_mean();
|
|
|
|
|
|
let time_unit = self
|
|
|
|
|
|
.options
|
|
|
|
|
|
.time_unit
|
|
|
|
|
|
.unwrap_or(t_wall_clock_mean.suitable_unit());
|
|
|
|
|
|
let mean = t_wall_clock_mean.format(time_unit);
|
2022-02-21 08:46:10 +01:00
|
|
|
|
format!("Current estimate: {}", mean.to_string().green())
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
if let Some(bar) = progress_bar.as_ref() {
|
|
|
|
|
|
bar.set_message(msg.to_owned())
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-10-05 09:47:09 +02:00
|
|
|
|
let res = self.executor.run_command_and_measure(
|
2024-11-10 22:21:22 +01:00
|
|
|
|
self.command,
|
2026-10-05 12:40:33 +02:00
|
|
|
|
benchmark_iteration,
|
2024-11-10 22:21:22 +01:00
|
|
|
|
None,
|
2024-11-11 22:18:19 +01:00
|
|
|
|
output_policy,
|
2024-11-10 22:21:22 +01:00
|
|
|
|
)?;
|
2026-10-05 10:09:41 +02:00
|
|
|
|
let success = res.exit_status.success();
|
2022-02-21 08:46:10 +01:00
|
|
|
|
|
2026-10-05 10:10:09 +02:00
|
|
|
|
measurements.push(res);
|
2022-02-21 08:46:10 +01:00
|
|
|
|
|
|
|
|
|
|
all_succeeded = all_succeeded && success;
|
|
|
|
|
|
|
|
|
|
|
|
if let Some(bar) = progress_bar.as_ref() {
|
|
|
|
|
|
bar.inc(1)
|
|
|
|
|
|
}
|
2024-01-21 19:27:08 +00:00
|
|
|
|
|
2025-03-13 08:45:56 +00:00
|
|
|
|
run_conclusion_command(benchmark_iteration)?;
|
2022-02-21 08:46:10 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if let Some(bar) = progress_bar.as_ref() {
|
|
|
|
|
|
bar.finish_and_clear()
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Compute statistical quantities
|
2026-10-05 10:10:09 +02:00
|
|
|
|
let t_num = measurements.len();
|
|
|
|
|
|
let t_mean = measurements.time_wall_clock_mean();
|
|
|
|
|
|
let t_stddev = measurements.stddev();
|
|
|
|
|
|
let t_min = measurements.min();
|
|
|
|
|
|
let t_max = measurements.max();
|
2022-02-21 08:46:10 +01:00
|
|
|
|
|
2026-10-05 10:10:09 +02:00
|
|
|
|
let user_mean = measurements.time_user_mean();
|
|
|
|
|
|
let system_mean = measurements.time_system_mean();
|
2022-02-21 08:46:10 +01:00
|
|
|
|
|
|
|
|
|
|
// Formatting and console output
|
2026-10-05 11:46:49 +02:00
|
|
|
|
let time_unit = self.options.time_unit.unwrap_or(t_mean.suitable_unit());
|
|
|
|
|
|
let mean_str = t_mean.format(time_unit);
|
|
|
|
|
|
let min_str = t_min.format(time_unit);
|
|
|
|
|
|
let max_str = t_max.format(time_unit);
|
2024-05-31 13:26:35 -07:00
|
|
|
|
let num_str = format!("{t_num} runs");
|
2022-02-21 08:46:10 +01:00
|
|
|
|
|
2026-10-05 11:46:49 +02:00
|
|
|
|
let user_str = user_mean.format(time_unit);
|
|
|
|
|
|
let system_str = system_mean.format(time_unit);
|
2022-02-21 08:46:10 +01:00
|
|
|
|
|
|
|
|
|
|
if self.options.output_style != OutputStyleOption::Disabled {
|
2026-10-02 17:18:56 +08:00
|
|
|
|
let mut stdout = io::stdout().lock();
|
2026-10-05 10:10:09 +02:00
|
|
|
|
if measurements.len() == 1 {
|
2026-10-02 17:18:56 +08:00
|
|
|
|
console_writeln!(
|
|
|
|
|
|
stdout,
|
2022-02-21 08:46:10 +01:00
|
|
|
|
" Time ({} ≡): {:>8} {:>8} [User: {}, System: {}]",
|
|
|
|
|
|
"abs".green().bold(),
|
|
|
|
|
|
mean_str.green().bold(),
|
2022-05-17 22:57:10 +02:00
|
|
|
|
" ", // alignment
|
2022-02-21 08:46:10 +01:00
|
|
|
|
user_str.blue(),
|
|
|
|
|
|
system_str.blue()
|
2026-10-02 17:18:56 +08:00
|
|
|
|
)?;
|
2022-02-21 08:46:10 +01:00
|
|
|
|
} else {
|
2026-10-05 11:46:49 +02:00
|
|
|
|
let stddev_str = t_stddev.unwrap().format(time_unit);
|
2022-02-21 08:46:10 +01:00
|
|
|
|
|
2026-10-02 17:18:56 +08:00
|
|
|
|
console_writeln!(
|
|
|
|
|
|
stdout,
|
2022-02-21 08:46:10 +01:00
|
|
|
|
" Time ({} ± {}): {:>8} ± {:>8} [User: {}, System: {}]",
|
|
|
|
|
|
"mean".green().bold(),
|
|
|
|
|
|
"σ".green(),
|
|
|
|
|
|
mean_str.green().bold(),
|
|
|
|
|
|
stddev_str.green(),
|
|
|
|
|
|
user_str.blue(),
|
|
|
|
|
|
system_str.blue()
|
2026-10-02 17:18:56 +08:00
|
|
|
|
)?;
|
2022-02-21 08:46:10 +01:00
|
|
|
|
|
2026-10-02 17:18:56 +08:00
|
|
|
|
console_writeln!(
|
|
|
|
|
|
stdout,
|
2022-02-21 08:46:10 +01:00
|
|
|
|
" Range ({} … {}): {:>8} … {:>8} {}",
|
|
|
|
|
|
"min".cyan(),
|
|
|
|
|
|
"max".purple(),
|
|
|
|
|
|
min_str.cyan(),
|
|
|
|
|
|
max_str.purple(),
|
|
|
|
|
|
num_str.dimmed()
|
2026-10-02 17:18:56 +08:00
|
|
|
|
)?;
|
2022-02-21 08:46:10 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Warnings
|
|
|
|
|
|
let mut warnings = vec![];
|
|
|
|
|
|
|
|
|
|
|
|
// Check execution time
|
2022-02-22 13:31:03 +01:00
|
|
|
|
if matches!(self.options.executor_kind, ExecutorKind::Shell(_))
|
2026-10-05 10:10:09 +02:00
|
|
|
|
&& measurements
|
|
|
|
|
|
.wall_clock_times()
|
|
|
|
|
|
.any(|t| t < MIN_EXECUTION_TIME)
|
2022-02-22 13:31:03 +01:00
|
|
|
|
{
|
2022-02-21 08:46:10 +01:00
|
|
|
|
warnings.push(Warnings::FastExecutionTime);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-05-18 16:22:22 +03:00
|
|
|
|
// Check program exit codes
|
2022-02-21 08:46:10 +01:00
|
|
|
|
if !all_succeeded {
|
|
|
|
|
|
warnings.push(Warnings::NonZeroExitCode);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Run outlier detection
|
2026-10-05 10:10:09 +02:00
|
|
|
|
let scores = measurements.modified_zscores();
|
2022-11-20 21:18:03 +01:00
|
|
|
|
|
|
|
|
|
|
let outlier_warning_options = OutlierWarningOptions {
|
|
|
|
|
|
warmup_in_use: self.options.warmup_count > 0,
|
|
|
|
|
|
prepare_in_use: self
|
|
|
|
|
|
.options
|
|
|
|
|
|
.preparation_command
|
|
|
|
|
|
.as_ref()
|
|
|
|
|
|
.map(|v| v.len())
|
|
|
|
|
|
.unwrap_or(0)
|
|
|
|
|
|
> 0,
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2022-02-21 08:46:10 +01:00
|
|
|
|
if scores[0] > OUTLIER_THRESHOLD {
|
2022-11-20 21:18:03 +01:00
|
|
|
|
warnings.push(Warnings::SlowInitialRun(
|
2026-10-05 10:10:09 +02:00
|
|
|
|
measurements.wall_clock_times().next().unwrap(),
|
2022-11-20 21:18:03 +01:00
|
|
|
|
outlier_warning_options,
|
|
|
|
|
|
));
|
2022-02-21 08:46:10 +01:00
|
|
|
|
} else if scores.iter().any(|&s| s.abs() > OUTLIER_THRESHOLD) {
|
2022-11-20 21:18:03 +01:00
|
|
|
|
warnings.push(Warnings::OutliersDetected(outlier_warning_options));
|
2022-02-21 08:46:10 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if !warnings.is_empty() {
|
2026-10-02 17:18:56 +08:00
|
|
|
|
let mut stderr = io::stderr().lock();
|
|
|
|
|
|
console_writeln!(stderr, " ")?;
|
2022-02-21 08:46:10 +01:00
|
|
|
|
|
|
|
|
|
|
for warning in &warnings {
|
2026-10-02 17:18:56 +08:00
|
|
|
|
console_writeln!(stderr, " {}: {}", "Warning".yellow(), warning)?;
|
2022-02-21 08:46:10 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if self.options.output_style != OutputStyleOption::Disabled {
|
2026-10-02 17:18:56 +08:00
|
|
|
|
console_writeln!(io::stdout(), " ")?;
|
2022-02-21 08:46:10 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-11-11 22:18:19 +01:00
|
|
|
|
self.run_cleanup_command(self.command.get_parameters().iter().cloned(), output_policy)?;
|
2022-02-21 08:46:10 +01:00
|
|
|
|
|
|
|
|
|
|
Ok(BenchmarkResult {
|
2023-04-20 21:32:06 +02:00
|
|
|
|
command: self.command.get_name(),
|
|
|
|
|
|
command_with_unused_parameters: self.command.get_name_with_unused_parameters(),
|
2026-10-05 12:46:10 +02:00
|
|
|
|
measurements,
|
2022-02-21 08:46:10 +01:00
|
|
|
|
parameters: self
|
|
|
|
|
|
.command
|
|
|
|
|
|
.get_parameters()
|
|
|
|
|
|
.iter()
|
2026-10-05 12:35:24 +02:00
|
|
|
|
.map(|(name, value)| {
|
|
|
|
|
|
(
|
|
|
|
|
|
name.to_string(),
|
|
|
|
|
|
Parameter {
|
|
|
|
|
|
value: value.to_string(),
|
|
|
|
|
|
is_unused: self.command.is_parameter_unused(name),
|
|
|
|
|
|
},
|
|
|
|
|
|
)
|
|
|
|
|
|
})
|
2022-02-21 08:46:10 +01:00
|
|
|
|
.collect(),
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|