Extract typed quantity formatting

This commit is contained in:
David Peter committed 2026-10-05 11:46:49 +02:00
1 parent 862625fb3d
commit 6f557e0494
6 files changed
+304 -129

No files matched your search

+4 -4
View File
@@ -1,7 +1,7 @@
use std::fmt;
use crate::benchmark::MIN_EXECUTION_TIME;
use crate::quantity::{format_duration, second, Time};
use crate::quantity::{FormatQuantity, Time, TimeUnit};
pub struct OutlierWarningOptions {
pub warmup_in_use: bool,
@@ -21,11 +21,11 @@ impl fmt::Display for Warnings {
match *self {
Warnings::FastExecutionTime => write!(
f,
"Command took less than {:.0} ms to complete. Note that the results might be \
"Command took less than {} 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.",
MIN_EXECUTION_TIME.get::<second>() * 1e3
MIN_EXECUTION_TIME.format_with_precision(TimeUnit::MilliSecond, 0)
),
Warnings::NonZeroExitCode => write!(f, "Ignoring non-zero exit code."),
Warnings::SlowInitialRun(time_first_run, ref options) => write!(
@@ -33,7 +33,7 @@ impl fmt::Display for Warnings {
"The first benchmarking run for this command was significantly slower than the \
rest ({time}). This could be caused by (filesystem) caches that were not filled until \
after the first run. {hints}",
time=format_duration(time_first_run.get::<second>(), None),
time=time_first_run.format_auto(),
hints=match (options.warmup_in_use, options.prepare_in_use) {
(true, true) => "You are already using both the '--warmup' option as well \
as the '--prepare' option. Consider re-running the benchmark on a quiet system. \