2018-01-24 20:12:17 +01:00
|
|
|
use std::fmt;
|
|
|
|
|
|
2021-08-24 22:16:40 +02:00
|
|
|
use crate::benchmark::MIN_EXECUTION_TIME;
|
2022-02-06 19:40:54 +01:00
|
|
|
use crate::output::format::format_duration;
|
2022-02-06 20:01:41 +01:00
|
|
|
use crate::util::units::Second;
|
2018-01-24 20:12:17 +01:00
|
|
|
|
|
|
|
|
/// A list of all possible warnings
|
|
|
|
|
pub enum Warnings {
|
|
|
|
|
FastExecutionTime,
|
|
|
|
|
NonZeroExitCode,
|
|
|
|
|
SlowInitialRun(Second),
|
|
|
|
|
OutliersDetected,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl fmt::Display for Warnings {
|
2019-05-07 11:55:38 +02:00
|
|
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
2018-01-24 20:12:17 +01:00
|
|
|
match *self {
|
|
|
|
|
Warnings::FastExecutionTime => write!(
|
|
|
|
|
f,
|
2022-03-05 12:47:26 +01:00
|
|
|
"Command took less than {:.0} ms to complete. Note that the results might be \
|
|
|
|
|
inaccurate because hyperfine can not calibrate the shell startup time much \
|
|
|
|
|
more precise than this limit. You can try to use the `-N`/`--shell=none` \
|
|
|
|
|
option to disable the shell completely.",
|
2018-01-24 20:12:17 +01:00
|
|
|
MIN_EXECUTION_TIME * 1e3
|
|
|
|
|
),
|
|
|
|
|
Warnings::NonZeroExitCode => write!(f, "Ignoring non-zero exit code."),
|
|
|
|
|
Warnings::SlowInitialRun(t_first) => write!(
|
|
|
|
|
f,
|
|
|
|
|
"The first benchmarking run for this command was significantly slower than the \
|
|
|
|
|
rest ({}). This could be caused by (filesystem) caches that were not filled until \
|
|
|
|
|
after the first run. You should consider using the '--warmup' option to fill \
|
|
|
|
|
those caches before the actual benchmark. Alternatively, use the '--prepare' \
|
|
|
|
|
option to clear the caches before each timing run.",
|
|
|
|
|
format_duration(t_first, None)
|
|
|
|
|
),
|
|
|
|
|
Warnings::OutliersDetected => write!(
|
|
|
|
|
f,
|
|
|
|
|
"Statistical outliers were detected. Consider re-running this benchmark on a quiet \
|
|
|
|
|
PC without any interferences from other programs. It might help to use the \
|
|
|
|
|
'--warmup' or '--prepare' options."
|
|
|
|
|
),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|