warnings.rs
This file
Path
src/output/warnings.rs
65 lines · 3.4 KiB · Rust
Last changed by
Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
History of this fileTake it
1use std::fmt;23use crate::benchmark::MIN_EXECUTION_TIME;4use crate::metric::{Metric, MetricSelection};5use crate::quantity::millisecond;67pub struct OutlierWarningOptions {8 pub warmup_in_use: bool,9 pub prepare_in_use: bool,10}1112/// A list of all possible warnings13pub enum Warnings {14 FastExecutionTime,15 NonZeroExitCode,16 InitialRunOutlier(MetricSelection, f64, OutlierWarningOptions),17}1819impl fmt::Display for Warnings {20 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {21 match *self {22 Warnings::FastExecutionTime => write!(23 f,24 "Command took less than {} ms to complete. Note that the wall-clock measurements might be \25 inaccurate because hyperfine can not calibrate the shell startup time much \26 more precise than this limit. You can try to use the `-N`/`--shell=none` \27 option to disable the shell completely.",28 MIN_EXECUTION_TIME.get::<millisecond>()29 ),30 Warnings::NonZeroExitCode => write!(f, "Ignoring non-zero exit code."),31 Warnings::InitialRunOutlier(selection, value, _) if selection.metric != Metric::TimeWallClock => write!(32 f,33 "The first benchmarking run for this command had an unusually high value for the primary '{}' metric ({}) compared with the rest.",34 selection.metric.name(),35 selection.display_unit(value).format(value),36 ),37 Warnings::InitialRunOutlier(selection, value, ref options) => write!(38 f,39 "The first benchmarking run for this command was significantly slower than the \40 rest ({time}). This could be caused by (filesystem) caches that were not filled until \41 after the first run. {hints}",42 time=selection.display_unit(value).format(value),43 hints=match (options.warmup_in_use, options.prepare_in_use) {44 (true, true) => "You are already using both the '--warmup' option as well \45 as the '--prepare' option. Consider re-running the benchmark on a quiet system. \46 Maybe it was a random outlier. Alternatively, consider increasing the warmup \47 count.",48 (true, false) => "You are already using the '--warmup' option which helps \49 to fill these caches before the actual benchmark. You can either try to \50 increase the warmup count further or re-run this benchmark on a quiet system \51 in case it was a random outlier. Alternatively, consider using the '--prepare' \52 option to clear the caches before each timing run.",53 (false, true) => "You are already using the '--prepare' option which can \54 be used to clear caches. If you did not use a cache-clearing command with \55 '--prepare', you can either try that or consider using the '--warmup' option \56 to fill those caches before the actual benchmark.",57 (false, false) => "You should consider using the '--warmup' option to fill \58 those caches before the actual benchmark. Alternatively, use the '--prepare' \59 option to clear the caches before each timing run."60 }61 ),6263 }64 }65}