mirror of
https://github.com/sharkdp/hyperfine.git
synced 2026-11-01 08:50:19 +00:00
Implement TimeUnit functions via uom
This commit is contained in:
1 parent
71365c227e
commit
418e43a652
8 files changed
+20
-25
No files matched your search
@@ -138,7 +138,7 @@ impl Measurements {
|
||||
&self
|
||||
.wall_clock_times()
|
||||
.iter()
|
||||
.map(|t| t.value_in::<second>()) // TODO
|
||||
.map(|t| t.value_in(second)) // TODO
|
||||
.collect::<Vec<_>>(),
|
||||
)
|
||||
}
|
||||
|
||||
+2
-4
@@ -291,15 +291,13 @@ fn build_command() -> Command {
|
||||
.short('u')
|
||||
.action(ArgAction::Set)
|
||||
.value_name("UNIT")
|
||||
.value_parser(["µs", "us", "microsecond", "microseconds", "ms", "millisecond", "milliseconds", "s", "second", "seconds", "min", "minute", "minutes", "h", "hour", "hours"])
|
||||
.value_parser(["µs", "us", "microsecond", "microseconds", "ms", "millisecond", "milliseconds", "s", "second", "seconds"])
|
||||
.help("Set the time unit to be used. If the option is not given, the time unit is determined automatically. \
|
||||
This option affects the standard output as well as all export formats except for CSV and JSON.\n\
|
||||
Possible values:\n \
|
||||
* 'µs', 'us', 'microsecond', 'microseconds'\n \
|
||||
* 'ms', 'millisecond', 'milliseconds'\n \
|
||||
* 's', 'second', 'seconds'\n \
|
||||
* 'min', 'minute', 'minutes'\n \
|
||||
* 'h', 'hour', 'hours'"),
|
||||
* 's', 'second', 'seconds'"),
|
||||
)
|
||||
.arg(
|
||||
Arg::new("export-asciidoc")
|
||||
|
||||
+3
-3
@@ -6,7 +6,7 @@ use super::Exporter;
|
||||
use crate::benchmark::benchmark_result::BenchmarkResult;
|
||||
use crate::options::SortOrder;
|
||||
use crate::quantity::{second, TimeQuantity};
|
||||
use crate::util::units::Unit;
|
||||
use crate::util::units::TimeUnit;
|
||||
|
||||
use anyhow::Result;
|
||||
|
||||
@@ -17,7 +17,7 @@ impl Exporter for CsvExporter {
|
||||
fn serialize(
|
||||
&self,
|
||||
results: &[BenchmarkResult],
|
||||
_unit: Option<TimeUnit>,
|
||||
_time_unit: Option<TimeUnit>,
|
||||
_sort_order: SortOrder,
|
||||
_reference_index: Option<usize>,
|
||||
) -> Result<Vec<u8>> {
|
||||
@@ -53,7 +53,7 @@ impl Exporter for CsvExporter {
|
||||
res.measurements.min(),
|
||||
res.measurements.max(),
|
||||
] {
|
||||
fields.push(Cow::Owned(f.value_in::<second>().to_string().into_bytes()))
|
||||
fields.push(Cow::Owned(f.value_in(second).to_string().into_bytes()))
|
||||
}
|
||||
for v in res.parameters.values() {
|
||||
fields.push(Cow::Borrowed(v.value.as_bytes()))
|
||||
|
||||
+2
-2
@@ -4,7 +4,7 @@ use serde_json::to_vec_pretty;
|
||||
use super::Exporter;
|
||||
use crate::benchmark::benchmark_result::BenchmarkResult;
|
||||
use crate::options::SortOrder;
|
||||
use crate::quantity::TimeUnit;
|
||||
use crate::util::units::TimeUnit;
|
||||
|
||||
use anyhow::Result;
|
||||
|
||||
@@ -20,7 +20,7 @@ impl Exporter for JsonExporter {
|
||||
fn serialize(
|
||||
&self,
|
||||
results: &[BenchmarkResult],
|
||||
_unit: Option<TimeUnit>,
|
||||
_time_unit: Option<TimeUnit>,
|
||||
_sort_order: SortOrder,
|
||||
_reference_index: Option<usize>,
|
||||
) -> Result<Vec<u8>> {
|
||||
|
||||
@@ -16,12 +16,12 @@ pub trait MarkupExporter {
|
||||
fn table_results(
|
||||
&self,
|
||||
entries: &[BenchmarkResultWithRelativeSpeed],
|
||||
unit: TimeUnit,
|
||||
time_unit: TimeUnit,
|
||||
reference_pending: bool,
|
||||
explicit_reference: bool,
|
||||
) -> String {
|
||||
// prepare table header strings
|
||||
let notation = format!("[{}]", unit.short_name());
|
||||
let notation = format!("[{}]", time_unit.short_name());
|
||||
|
||||
// prepare table cells alignment
|
||||
let cells_alignment = [
|
||||
@@ -51,14 +51,14 @@ pub trait MarkupExporter {
|
||||
let result = &entry.result;
|
||||
// prepare data row strings
|
||||
let cmd_str = result.command_with_unused_parameters().replace('|', "\\|");
|
||||
let mean_str = format_duration_value(result.mean_wall_clock_time(), Some(unit)).0;
|
||||
let mean_str = format_duration_value(result.mean_wall_clock_time(), Some(time_unit)).0;
|
||||
let stddev_str = if let Some(stddev) = result.measurements.stddev() {
|
||||
format!(" ± {}", format_duration_value(stddev, Some(unit)).0)
|
||||
format!(" ± {}", format_duration_value(stddev, Some(time_unit)).0)
|
||||
} else {
|
||||
"".into()
|
||||
};
|
||||
let min_str = result.measurements.min().format_value(unit);
|
||||
let max_str = result.measurements.max().format_value(unit);
|
||||
let min_str = result.measurements.min().format_value(time_unit);
|
||||
let max_str = result.measurements.max().format_value(time_unit);
|
||||
// The ratio of two zero times is undefined, even if they compare equal.
|
||||
let relative_unavailable = reference_pending
|
||||
|| (explicit_reference
|
||||
|
||||
+2
-3
@@ -18,8 +18,7 @@ use self::orgmode::OrgmodeExporter;
|
||||
|
||||
use crate::benchmark::benchmark_result::BenchmarkResult;
|
||||
use crate::options::SortOrder;
|
||||
use crate::output::console_writeln;
|
||||
use crate::quantity::TimeUnit;
|
||||
use crate::util::units::TimeUnit;
|
||||
|
||||
use anyhow::{Context, Result};
|
||||
use clap::ArgMatches;
|
||||
@@ -49,7 +48,7 @@ trait Exporter {
|
||||
fn serialize(
|
||||
&self,
|
||||
results: &[BenchmarkResult],
|
||||
unit: Option<TimeUnit>,
|
||||
time_unit: Option<TimeUnit>,
|
||||
sort_order: SortOrder,
|
||||
reference_index: Option<usize>,
|
||||
) -> Result<Vec<u8>>;
|
||||
|
||||
+3
-3
@@ -4,7 +4,7 @@ use crate::benchmark::measurement::{Measurement, Measurements};
|
||||
use crate::export::asciidoc::AsciidocExporter;
|
||||
use crate::export::orgmode::OrgmodeExporter;
|
||||
use crate::quantity::{Information, InformationQuantity, Time, TimeQuantity};
|
||||
use crate::util::units::Unit;
|
||||
use crate::util::units::TimeUnit;
|
||||
use crate::{export::markdown::MarkdownExporter, options::SortOrder};
|
||||
use std::collections::BTreeMap;
|
||||
use std::process::ExitStatus;
|
||||
@@ -379,14 +379,14 @@ fn test_markup_export_manual_s() {
|
||||
},
|
||||
];
|
||||
|
||||
insta::assert_snapshot!(get_output::<MarkdownExporter>(&results, Some(Unit::Second), SortOrder::Command), @r#"
|
||||
insta::assert_snapshot!(get_output::<MarkdownExporter>(&results, Some(TimeUnit::Second), SortOrder::Command), @r#"
|
||||
| Command | Mean [s] | Min [s] | Max [s] | Relative |
|
||||
|:---|---:|---:|---:|---:|
|
||||
| `sleep 2` | 2.020 ± 0.010 | 2.010 | 2.030 | 16.83 ± 1.41 |
|
||||
| `sleep 0.1` | 0.120 ± 0.010 | 0.110 | 0.130 | 1.00 |
|
||||
"#);
|
||||
|
||||
insta::assert_snapshot!(get_output::<MarkdownExporter>(&results, Some(Unit::Second), SortOrder::MeanTime), @r#"
|
||||
insta::assert_snapshot!(get_output::<MarkdownExporter>(&results, Some(TimeUnit::Second), SortOrder::MeanTime), @r#"
|
||||
| Command | Mean [s] | Min [s] | Max [s] | Relative |
|
||||
|:---|---:|---:|---:|---:|
|
||||
| `sleep 0.1` | 0.120 ± 0.010 | 0.110 | 0.130 | 1.00 |
|
||||
|
||||
+1
-3
@@ -10,7 +10,7 @@ use clap::ArgMatches;
|
||||
use crate::command::Commands;
|
||||
use crate::error::OptionsError;
|
||||
use crate::quantity::{Time, TimeQuantity};
|
||||
use crate::util::units::Unit;
|
||||
use crate::util::units::TimeUnit;
|
||||
|
||||
use anyhow::Result;
|
||||
|
||||
@@ -437,8 +437,6 @@ impl Options {
|
||||
Some("µs" | "us" | "microsecond" | "microseconds") => Some(TimeUnit::MicroSecond),
|
||||
Some("ms" | "millisecond" | "milliseconds") => Some(TimeUnit::MilliSecond),
|
||||
Some("s" | "second" | "seconds") => Some(TimeUnit::Second),
|
||||
Some("min" | "minute" | "minutes") => Some(TimeUnit::Minute),
|
||||
Some("h" | "hour" | "hours") => Some(TimeUnit::Hour),
|
||||
_ => None,
|
||||
};
|
||||
|
||||
|
||||
Reference in new issue
Block a user