mirror of
https://github.com/sharkdp/hyperfine.git
synced 2026-11-01 17:00:18 +00:00
Consistent display name
This commit is contained in:
1 parent
eedec07812
commit
579b762790
8 files changed
+34
-40
No files matched your search
@@ -5,24 +5,35 @@ use serde::Serialize;
|
||||
use crate::benchmark::measurement::Measurements;
|
||||
use crate::quantity::Time;
|
||||
|
||||
/// Parameter value and whether it was used in the command line template
|
||||
/// Parameter value
|
||||
#[derive(Debug, Default, Clone, Serialize, PartialEq)]
|
||||
pub struct Parameter {
|
||||
pub value: String,
|
||||
#[serde(skip_serializing)]
|
||||
pub is_unused: bool,
|
||||
}
|
||||
|
||||
/// Meta data and performance metrics for a single benchmark
|
||||
#[derive(Debug, Default, Clone, Serialize, PartialEq)]
|
||||
pub struct BenchmarkResult {
|
||||
/// The expanded command line being benchmarked
|
||||
/// The command line being benchmarked, after parameter substitution.
|
||||
/// For example, `sleep {duration}` with `duration=1` becomes `sleep 1`,
|
||||
/// regardless of any custom name.
|
||||
pub command: String,
|
||||
|
||||
/// The display name, when it differs from the command line
|
||||
/// The custom name after parameter substitution, if it differs from `command`.
|
||||
/// For example, `--command-name="wait {duration}s"` with `duration=1`
|
||||
/// produces `Some("wait 1s")`. Without a custom name, or when the expanded
|
||||
/// name equals `command`, this is `None`.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub name: Option<String>,
|
||||
|
||||
/// The custom name (or `command`), followed by parameters not used in the
|
||||
/// command template, in command-line order. For example, `sleep {duration}`
|
||||
/// with `duration=1`, `branch=main`, and the custom name `wait {duration}s`
|
||||
/// produces `wait 1s (branch = main)`. Without the custom name, this is
|
||||
/// `sleep 1 (branch = main)`. Used in summaries and table exports.
|
||||
#[serde(skip_serializing)]
|
||||
pub display_name: String,
|
||||
|
||||
/// Performance metric measurements and exit codes for each run
|
||||
#[serde(flatten)]
|
||||
pub measurements: Measurements,
|
||||
@@ -41,24 +52,4 @@ impl BenchmarkResult {
|
||||
pub fn mean_wall_clock_time(&self) -> Time {
|
||||
self.measurements.time_wall_clock_mean()
|
||||
}
|
||||
|
||||
/// The display name of the command, possibly including a list of
|
||||
/// parameters that were not used in the command line template.
|
||||
pub fn command_with_unused_parameters(&self) -> String {
|
||||
let parameters = self
|
||||
.parameters
|
||||
.iter()
|
||||
.filter(|(_, parameter)| parameter.is_unused)
|
||||
.fold(String::new(), |output, (name, parameter)| {
|
||||
output + &format!("{name} = {value}, ", value = parameter.value)
|
||||
});
|
||||
let parameters = parameters.trim_end_matches(", ");
|
||||
let parameters = if parameters.is_empty() {
|
||||
"".into()
|
||||
} else {
|
||||
format!(" ({parameters})")
|
||||
};
|
||||
|
||||
format!("{}{}", self.get_name(), parameters)
|
||||
}
|
||||
}
|
||||
@@ -482,6 +482,7 @@ impl<'a> Benchmark<'a> {
|
||||
Ok(BenchmarkResult {
|
||||
command,
|
||||
name,
|
||||
display_name: self.command.get_name_with_unused_parameters(),
|
||||
measurements,
|
||||
parameters: self
|
||||
.command
|
||||
@@ -492,7 +493,6 @@ impl<'a> Benchmark<'a> {
|
||||
name.to_string(),
|
||||
Parameter {
|
||||
value: value.to_string(),
|
||||
is_unused: self.command.is_parameter_unused(name),
|
||||
},
|
||||
)
|
||||
})
|
||||
|
||||
@@ -158,6 +158,7 @@ fn create_result(name: &str, mean: f64) -> BenchmarkResult {
|
||||
|
||||
BenchmarkResult {
|
||||
command: name.into(),
|
||||
display_name: name.into(),
|
||||
name: None,
|
||||
measurements: Measurements {
|
||||
measurements: vec![Measurement {
|
||||
|
||||
@@ -89,11 +89,7 @@ impl<'a> Scheduler<'a> {
|
||||
let reference = annotated_results.iter().find(|r| r.is_reference).unwrap();
|
||||
let others = annotated_results.iter().filter(|r| !r.is_reference);
|
||||
|
||||
console_writeln!(
|
||||
stdout,
|
||||
" {} ran",
|
||||
reference.result.command_with_unused_parameters().cyan()
|
||||
)?;
|
||||
console_writeln!(stdout, " {} ran", reference.result.display_name.cyan())?;
|
||||
|
||||
for item in others {
|
||||
let stddev = if let Some(stddev) = item.relative_speed_stddev {
|
||||
@@ -122,7 +118,7 @@ impl<'a> Scheduler<'a> {
|
||||
stdout,
|
||||
"{} {}",
|
||||
comparator,
|
||||
&item.result.command_with_unused_parameters().magenta()
|
||||
&item.result.display_name.magenta()
|
||||
)?;
|
||||
}
|
||||
}
|
||||
@@ -146,7 +142,7 @@ impl<'a> Scheduler<'a> {
|
||||
} else {
|
||||
" ".into()
|
||||
},
|
||||
item.result.command_with_unused_parameters(),
|
||||
item.result.display_name,
|
||||
relationship,
|
||||
)?;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user