Skip to content
Myr

Quantity API cleanup

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by David Peter · committed by David Peter · parent 0257df9 · Browse files · 10 files+257 added−162 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

10 files+257 added−162 removed

  • other:+257 added−162 removed

10 files+257 added−162 removed

modified:src/benchmark/mod.rs+11 added-10 removed
14 unmodified lines
15use crate::options::{16 CmdFailureAction, CommandOutputPolicy, ExecutorKind, Options, OutputStyleOption,17};18use crate::outlier_detection::OUTLIER_THRESHOLD;19use crate::output::format::{format_duration, format_duration_unit};19use crate::output::console_writeln;20use crate::output::progress_bar::{21 finish_initial_measurement, get_progress_bar, start_initial_measurement,22};
306 unmodified lines
329 for i in 0..count_remaining {330 let benchmark_iteration = BenchmarkIteration::Benchmark(i + 1);331332 let msg = {334 let mean =335 format_duration(measurements.time_wall_clock_mean(), self.options.time_unit);333 let mean = measurements334 .time_wall_clock_mean()335 .format_auto(self.options.time_unit);336 format!("Current estimate: {}", mean.to_string().green())337 };338339 if let Some(bar) = progress_bar.as_ref() {
24 unmodified lines
364 bar.finish_and_clear()365 }366367 // Formatting and console output368 let (mean_str, time_unit) =369 format_duration_unit(measurements.time_wall_clock_mean(), self.options.time_unit);370 let min_str = format_duration(measurements.min(), Some(time_unit));371 let max_str = format_duration(measurements.max(), Some(time_unit));368 let (mean_str, time_unit) = measurements369 .time_wall_clock_mean()370 .format_auto_with_unit(self.options.time_unit);371 let min_str = measurements.min().format_auto(Some(time_unit));372 let max_str = measurements.max().format_auto(Some(time_unit));373 let num_str = format!("{num_runs} runs", num_runs = measurements.len());374374 let user_str = format_duration(measurements.time_user_mean(), Some(time_unit));375 let system_str = format_duration(measurements.time_system_mean(), Some(time_unit));375 let user_str = measurements.time_user_mean().format_auto(Some(time_unit));376 let system_str = measurements.time_system_mean().format_auto(Some(time_unit));377378 if self.options.output_style != OutputStyleOption::Disabled {379 if measurements.len() == 1 {380 println!(
4 unmodified lines
385 user_str.blue(),386 system_str.blue()387 )?;388 } else {388 let stddev_str = format_duration(measurements.stddev().unwrap(), Some(time_unit));389 let stddev_str = measurements.stddev().unwrap().format_auto(Some(time_unit));390391 console_writeln!(392 stdout,393 " Time ({} ± {}): {:>8} ± {:>8} [User: {}, System: {}]",
96 unmodified lines
modified:src/export/csv.rs+1 added-2 removed
3 unmodified lines
45use super::Exporter;6use crate::benchmark::benchmark_result::BenchmarkResult;7use crate::options::SortOrder;8use crate::quantity::{second, TimeQuantity};9use crate::util::units::TimeUnit;8use crate::quantity::{second, TimeQuantity, TimeUnit};910use anyhow::Result;1112#[derive(Default)]
169 unmodified lines
modified:src/export/json.rs+1 added-1 removed
2 unmodified lines
34use super::Exporter;5use crate::benchmark::benchmark_result::BenchmarkResult;6use crate::options::SortOrder;7use crate::util::units::TimeUnit;7use crate::quantity::TimeUnit;89use anyhow::Result;1011#[derive(Serialize, Debug)]
23 unmodified lines
modified:src/export/markup.rs+9 added-3 removed
49 unmodified lines
50 for entry in entries {51 let result = &entry.result;52 // prepare data row strings53 let cmd_str = result.command_with_unused_parameters().replace('|', "\\|");54 let mean_str = format_duration_value(result.mean_wall_clock_time(), Some(time_unit)).0;54 let mean_str = result55 .mean_wall_clock_time()56 .format_value_auto(Some(time_unit))57 .0;58 let stddev_str = if let Some(stddev) = result.measurements.stddev() {56 format!(" ± {}", format_duration_value(stddev, Some(time_unit)).0)59 format!(" ± {}", stddev.format_value_auto(Some(time_unit)).0)60 } else {61 "".into()62 };63 let min_str = result.measurements.min().format_value(time_unit);
52 unmodified lines
116117fn determine_unit_from_results(results: &[BenchmarkResult]) -> TimeUnit {118 if let Some(first_result) = results.first() {119 // Use the first BenchmarkResult entry to determine the unit for all entries.117 format_duration_value(first_result.mean_wall_clock_time(), None).1120 first_result121 .mean_wall_clock_time()122 .format_auto_with_unit(None)123 .1124 } else {125 // Default to `Second`.126 TimeUnit::Second127 }
25 unmodified lines
modified:src/export/mod.rs+1 added-1 removed
16 unmodified lines
17use self::orgmode::OrgmodeExporter;1819use crate::benchmark::benchmark_result::BenchmarkResult;20use crate::options::SortOrder;21use crate::util::units::TimeUnit;21use crate::quantity::TimeUnit;2223use anyhow::{Context, Result};24use clap::ArgMatches;25
150 unmodified lines
modified:src/export/tests.rs+1 added-2 removed
1 unmodified line
2use crate::benchmark::benchmark_result::BenchmarkResult;3use crate::benchmark::measurement::{Measurement, Measurements};4use crate::export::asciidoc::AsciidocExporter;5use crate::export::orgmode::OrgmodeExporter;6use crate::quantity::{byte, second, Information, Time, TimeQuantity};7use crate::util::units::TimeUnit;6use crate::quantity::{byte, second, Information, Time, TimeQuantity, TimeUnit};7use crate::{export::markdown::MarkdownExporter, options::SortOrder};8use std::collections::BTreeMap;9use std::process::ExitStatus;10
407 unmodified lines
modified:src/output/warnings.rs+3 added-4 removed
1use std::fmt;23use crate::benchmark::MIN_EXECUTION_TIME;4use crate::output::format::format_duration;5use crate::quantity::{millisecond, Time, TimeQuantity};4use crate::quantity::{Time, TimeQuantity, TimeUnit};56pub struct OutlierWarningOptions {7 pub warmup_in_use: bool,8 pub prepare_in_use: bool,
15 unmodified lines
24 "Command took less than {min_execution_time} to complete. Note that the results 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.",29 min_execution_time = MIN_EXECUTION_TIME.to_string(millisecond)28 min_execution_time = MIN_EXECUTION_TIME.format_value_in(TimeUnit::MilliSecond, 0)29 ),30 Warnings::NonZeroExitCode => write!(f, "Ignoring non-zero exit code."),31 Warnings::SlowInitialRun(time_first_run, ref options) => write!(32 f,33 "The first benchmarking run for this command was significantly slower than the \34 rest ({time}). This could be caused by (filesystem) caches that were not filled until \35 after the first run. {hints}",37 time=time_first_run.format_auto(),36 time=time_first_run.format_auto(None),37 hints=match (options.warmup_in_use, options.prepare_in_use) {38 (true, true) => "You are already using both the '--warmup' option as well \39 as the '--prepare' option. Consider re-running the benchmark on a quiet system. \40 Maybe it was a random outlier. Alternatively, consider increasing the warmup \
28 unmodified lines
modified:src/quantity/mod.rs+186 added-107 removed
1use core::f64;2use std::marker::PhantomData;33use uom::si;4use serde::ser::SerializeStruct;5use serde::Serializer;6use uom::{si, Conversion};78pub use uom::si::information::{byte, kibibyte};9pub use uom::si::ratio::ratio;10pub use uom::si::time::{hour, microsecond, millisecond, minute, nanosecond, second};1112pub use si::f64::Ratio;13pub use si::f64::Time;14pub use si::u64::Information;1516pub use si::f64::{Information, Ratio, Time};17pub use si::information::{byte, gibibyte, kibibyte, mebibyte, tebibyte};18pub use si::ratio::ratio;19pub use si::time::{hour, microsecond, millisecond, minute, nanosecond, second};20pub use uom::num_traits::Zero;2122pub use units::{InformationUnit, IsUnit, TimeUnit};2313pub mod statistics;24mod units;2516pub trait FormatQuantity {17 type Unit;26pub trait TimeQuantity {27 fn zero() -> Time {28 Time::new::<second>(0.0)29 }3019 fn suitable_unit(&self) -> Self::Unit;31 fn value_in<U>(&self, u: U) -> f6432 where33 U: si::time::Unit + Conversion<f64, T = f64>;3421 fn format_with_precision(&self, unit: Self::Unit, precision: usize) -> String;22 fn format(&self, unit: Self::Unit) -> String;23 fn format_auto(&self) -> String;24 fn format_value(&self, unit: Self::Unit) -> String;35 fn format_value_in(&self, time_unit: TimeUnit, precision: usize) -> String;36 fn format_auto(&self, time_unit: Option<TimeUnit>) -> String;37 fn format_auto_with_unit(&self, time_unit: Option<TimeUnit>) -> (String, TimeUnit);38 fn format_value_auto(&self, time_unit: Option<TimeUnit>) -> (String, TimeUnit);39}4027impl FormatQuantity for Time {28 type Unit = TimeUnit;2930 fn suitable_unit(&self) -> TimeUnit {31 if *self < Time::new::<millisecond>(1.0) {32 TimeUnit::MicroSecond33 } else if *self < Time::new::<second>(1.0) {34 TimeUnit::MilliSecond35 } else {36 TimeUnit::Second37 }41impl TimeQuantity for Time {42 fn value_in<U>(&self, _u: U) -> f6443 where44 U: si::time::Unit + Conversion<f64, T = f64>,45 {46 self.get::<U>()47 }4840 /// Format the time duration in the given unit with the given precision.41 fn format_with_precision(&self, u: TimeUnit, precision: usize) -> String {49 fn format_value_in(&self, u: TimeUnit, precision: usize) -> String {50 u.format(*self, precision)51 }5245 /// Format the time duration in the given unit.46 fn format(&self, unit: TimeUnit) -> String {47 let value = self.format_with_precision(unit, unit.preferred_precision());48 format!("{} {}", value, unit.short_name())53 /// Format the given duration as a string. The output-unit can be enforced by setting `unit` to54 /// `Some(target_unit)`. If `unit` is `None`, it will be determined automatically.55 fn format_auto(&self, time_unit: Option<TimeUnit>) -> String {56 self.format_auto_with_unit(time_unit).057 }5851 /// Format the given time duration. The unit will be determined automatically.52 fn format_auto(&self) -> String {53 self.format(self.suitable_unit())59 /// Like `format_duration`, but returns the target unit as well.60 fn format_auto_with_unit(&self, time_unit: Option<TimeUnit>) -> (String, TimeUnit) {61 let (out_str, out_unit) = self.format_value_auto(time_unit);6263 (format!("{} {}", out_str, out_unit.short_name()), out_unit)64 }6556 /// Like `format`, but without displaying the unit.57 fn format_value(&self, unit: TimeUnit) -> String {58 self.format_with_precision(unit, unit.preferred_precision())66 /// Like `format_duration`, but returns the target unit as well.67 fn format_value_auto(&self, time_unit: Option<TimeUnit>) -> (String, TimeUnit) {68 let (time_unit, precision) = if (*self < Time::new::<millisecond>(1.0)69 && time_unit.is_none())70 || time_unit == Some(TimeUnit::MicroSecond)71 {72 (TimeUnit::MicroSecond, 1)73 } else if (*self < Time::new::<second>(1.0) && time_unit.is_none())74 || time_unit == Some(TimeUnit::MilliSecond)75 {76 (TimeUnit::MilliSecond, 1)77 } else {78 let time_unit = time_unit.unwrap_or(TimeUnit::Second);79 let precision = if time_unit == TimeUnit::Second { 3 } else { 1 };8081 (time_unit, precision)82 };8384 (self.format_value_in(time_unit, precision), time_unit)85 }86}8788pub const fn const_time_from_seconds(value: f64) -> Time {
4 unmodified lines
93 value,94 }95}9671impl FormatQuantity for Information {72 type Unit = InformationUnit;7374 fn suitable_unit(&self) -> InformationUnit {75 if *self < Information::new::<kibibyte>(1.0) {76 InformationUnit::Byte77 } else if *self < Information::new::<mebibyte>(1.0) {78 InformationUnit::KibiByte79 } else if *self < Information::new::<gibibyte>(1.0) {80 InformationUnit::MebiByte81 } else {82 InformationUnit::GibiByte83 }97pub trait InformationQuantity {98 fn zero() -> Information {99 Information::new::<byte>(0)100 }10186 /// Format the information in the given unit with the given precision.87 fn format_with_precision(&self, u: InformationUnit, precision: usize) -> String {88 u.format(*self, precision)89 }102 fn value_in<U>(&self, u: U) -> u64103 where104 U: si::information::Unit + Conversion<u64, T = uom::num_rational::Ratio<u64>>;10591 /// Format the information in the given unit.92 fn format(&self, unit: InformationUnit) -> String {93 let value = self.format_with_precision(unit, unit.preferred_precision());94 format!("{} {}", value, unit.short_name())95 }106 fn to_string<U>(&self, u: U) -> String107 where108 U: si::information::Unit + Conversion<u64, T = uom::num_rational::Ratio<u64>>;109}11097 /// Format the given information. The unit will be determined automatically.98 fn format_auto(&self) -> String {99 self.format(self.suitable_unit())111impl InformationQuantity for Information {112 fn value_in<U>(&self, _u: U) -> u64113 where114 U: si::information::Unit + Conversion<u64, T = uom::num_rational::Ratio<u64>>,115 {116 self.get::<U>()117 }118102 /// Like `format`, but without displaying the unit.103 fn format_value(&self, unit: InformationUnit) -> String {104 self.format_with_precision(unit, unit.preferred_precision())119 fn to_string<U>(&self, u: U) -> String120 where121 U: si::information::Unit + Conversion<u64, T = uom::num_rational::Ratio<u64>>,122 {123 format!(124 "{}",125 self.into_format_args(u, uom::fmt::DisplayStyle::Abbreviation)126 )127 }128}129130pub fn serialize_time<S>(t: &Time, s: S) -> Result<S::Ok, S::Error>131where132 S: Serializer,133{134 let mut state = s.serialize_struct("Time", 3)?;135 state.serialize_field("value", &t.value)?;136 state.serialize_field("unit", "second")?;137 state.end()138}139140pub fn serialize_information<S>(i: &Information, s: S) -> Result<S::Ok, S::Error>141where142 S: Serializer,143{144 let mut state = s.serialize_struct("Information", 3)?;145 state.serialize_field("value", &i.value)?;146 state.serialize_field("unit", "byte")?;147 state.end()148}149150macro_rules! quantity_fn {151 ($name:ident, $unwrapped_values:ident, $body:expr) => {152 pub fn $name(values: &[Time]) -> Time {153 let $unwrapped_values: Vec<_> = values.iter().map(|q| q.value_in(second)).collect();154 let result_value = $body;155156 Time::new::<second>(result_value)157 }158 };159}160161quantity_fn!(mean, values, statistical::mean(&values));162quantity_fn!(median, values, statistical::median(&values));163quantity_fn!(min, values, crate::util::min_max::min(&values));164quantity_fn!(max, values, crate::util::min_max::max(&values));165quantity_fn!(standard_deviation, values, {166 let mean_value = statistical::mean(&values);167 statistical::standard_deviation(&values, Some(mean_value))168});169170#[test]171fn test_time() {172 let time = Time::new::<millisecond>(123.4);111 assert_eq!(time.get::<millisecond>(), 123.4);173 assert_eq!(time.value_in(millisecond), 123.4);174113 let time_s = time.get::<second>();175 let time_s = time.value_in(second);176 approx::assert_relative_eq!(time_s, 0.1234);177116 let time_us = time.get::<microsecond>();178 let time_us = time.value_in(microsecond);179 approx::assert_relative_eq!(time_us, 123400.0);180}181182#[test]183fn test_information() {122 use uom::si::information::pebibyte;184 let information = Information::new::<kibibyte>(8);185 assert_eq!(information.value_in(byte), 8192);186124 let information = Information::new::<kibibyte>(8.);125 assert_eq!(information.get::<byte>(), 8192.);187 let information_kib = information.value_in(kibibyte);188 assert_eq!(information_kib, 8);189}190127 let information_kib = information.get::<kibibyte>();128 assert_eq!(information_kib, 8.);191#[test]192fn test_format() {193 let time = Time::new::<millisecond>(123.4);194 assert_eq!(time.format_auto(Some(TimeUnit::Second)), "0.123 s");195 assert_eq!(time.format_auto(Some(TimeUnit::MilliSecond)), "123.4 ms");196 assert_eq!(time.format_auto(Some(TimeUnit::MicroSecond)), "123400.0 µs");197130 let largest_exactly_representable = Information::new::<byte>(9_007_199_254_740_992.);131 assert_eq!(largest_exactly_representable.get::<pebibyte>(), 8.);198 let peak_memory_usage = Information::new::<kibibyte>(8);199 assert_eq!(peak_memory_usage.to_string(byte), "8192 B");200 assert_eq!(peak_memory_usage.to_string(kibibyte), "8 KiB");201}202203#[test]135fn test_suiteable_unit_time() {136 assert_eq!(Time::new::<second>(1.3).suitable_unit(), TimeUnit::Second);137 assert_eq!(Time::new::<second>(1.0).suitable_unit(), TimeUnit::Second);138 assert_eq!(139 Time::new::<second>(0.999).suitable_unit(),140 TimeUnit::MilliSecond141 );142 assert_eq!(143 Time::new::<second>(0.0005).suitable_unit(),144 TimeUnit::MicroSecond145 );146 assert_eq!(147 Time::new::<second>(0.).suitable_unit(),148 TimeUnit::MicroSecond149 );150 assert_eq!(151 Time::new::<second>(1000.0).suitable_unit(),152 TimeUnit::Second153 );204fn test_mean() {205 let values = vec![206 Time::new::<millisecond>(123.4),207 Time::new::<millisecond>(234.5),208 ];209 let result = mean(&values);210 assert_eq!(result.format_auto(Some(TimeUnit::MilliSecond)), "178.9 ms");211}212213#[test]214fn test_format_duration() {215 let (out_str, out_unit) = Time::new::<second>(1.3).format_auto_with_unit(None);216217#[test]218fn test_suitable_unit_information() {219 assert_eq!(220 Information::new::<byte>(512.0).suitable_unit(),221 InformationUnit::Byte
11 unmodified lines
233 InformationUnit::GibiByte234 );235}236176#[test]177fn test_format() {178 let time = Time::new::<millisecond>(123.4);179 assert_eq!(time.format(TimeUnit::Second), "0.123 s");180 assert_eq!(time.format(TimeUnit::MilliSecond), "123.4 ms");181 assert_eq!(time.format_auto(), "123.4 ms");182 assert_eq!(time.format(TimeUnit::MicroSecond), "123400.0 µs");237 let (out_str, out_unit) = Time::new::<second>(1.0).format_auto_with_unit(None);238184 let peak_memory_usage = Information::new::<kibibyte>(8.);185 assert_eq!(peak_memory_usage.format_auto(), "8.0 KiB");186 assert_eq!(peak_memory_usage.format(InformationUnit::Byte), "8192 B");187 assert_eq!(188 peak_memory_usage.format(InformationUnit::KibiByte),189 "8.0 KiB"190 );239 assert_eq!("1.000 s", out_str);240 assert_eq!(TimeUnit::Second, out_unit);241242 let (out_str, out_unit) = Time::new::<second>(0.999).format_auto_with_unit(None);243244 assert_eq!("999.0 ms", out_str);245 assert_eq!(TimeUnit::MilliSecond, out_unit);246247 let (out_str, out_unit) = Time::new::<second>(0.0005).format_auto_with_unit(None);248249 assert_eq!("500.0 µs", out_str);250 assert_eq!(TimeUnit::MicroSecond, out_unit);251252 let (out_str, out_unit) = Time::new::<second>(0.).format_auto_with_unit(None);253254 assert_eq!("0.0 µs", out_str);255 assert_eq!(TimeUnit::MicroSecond, out_unit);256257 let (out_str, out_unit) = Time::new::<second>(1000.0).format_auto_with_unit(None);258259 assert_eq!("1000.000 s", out_str);260 assert_eq!(TimeUnit::Second, out_unit);261}262263#[test]264fn test_format_duration_unit_with_unit() {195 let out = Time::new::<second>(1.3).format(TimeUnit::Second);196 assert_eq!("1.300 s", out);265 let (out_str, out_unit) =266 Time::new::<second>(1.3).format_auto_with_unit(Some(TimeUnit::Second));267268 let out = Time::new::<second>(1.3).format(TimeUnit::MilliSecond);269 assert_eq!("1300.0 ms", out);270201 let out = Time::new::<second>(1.3).format(TimeUnit::MicroSecond);202 assert_eq!("1300000.0 µs", out);271 let (out_str, out_unit) =272 Time::new::<second>(1.3).format_auto_with_unit(Some(TimeUnit::MilliSecond));273274 assert_eq!("1300.0 ms", out_str);275 assert_eq!(TimeUnit::MilliSecond, out_unit);276277 let (out_str, out_unit) =278 Time::new::<second>(1.3).format_auto_with_unit(Some(TimeUnit::MicroSecond));279280 assert_eq!("1300000.0 µs", out_str);281 assert_eq!(TimeUnit::MicroSecond, out_unit);282}
modified:src/quantity/units.rs+43 added-30 removed
21 unmodified lines
22 self.dispatch().format_value(value, precision)23 }24}2526use std::marker::PhantomData;2728use crate::quantity::{hour, microsecond, millisecond, minute, second, Time};2930/// Supported time units31#[derive(Debug, Clone, Copy, PartialEq, Eq)]32pub enum TimeUnit {33 MicroSecond,
2 unmodified lines
36 Minute,37 Hour,38}3936impl IsUnit for TimeUnit {37 type Quantity = Time;40struct Dispatcher<U: uom::si::time::Unit + uom::Conversion<f64, T = f64>> {41 u: PhantomData<U>,42}4339 fn dispatch(&self) -> Box<dyn UnitImpl<Quantity = Time>> {40 match self {41 TimeUnit::MicroSecond => Box::new(TimeUnitDispatcher::<microsecond>::new()),42 TimeUnit::MilliSecond => Box::new(TimeUnitDispatcher::<millisecond>::new()),43 TimeUnit::Second => Box::new(TimeUnitDispatcher::<second>::new()),44 TimeUnit::Minute => Box::new(TimeUnitDispatcher::<minute>::new()),45 TimeUnit::Hour => Box::new(TimeUnitDispatcher::<hour>::new()),46 }44impl<U: uom::si::time::Unit + uom::Conversion<f64, T = f64>> Dispatcher<U> {45 fn new() -> Self {46 Dispatcher { u: PhantomData }47 }48}4949 fn preferred_precision(&self) -> usize {50trait UnitImpl {51 fn short_name(&self) -> &'static str;52 fn format_value(&self, value: Time, precision: usize) -> String;53}5455impl<U: uom::si::time::Unit + uom::Conversion<f64, T = f64>> UnitImpl for Dispatcher<U> {56 fn short_name(&self) -> &'static str {57 U::abbreviation()58 }5960 fn format_value(&self, value: Time, precision: usize) -> String {61 format!("{value:.precision$}", value = value.get::<U>())62 }63}6465impl TimeUnit {66 fn dispatch(self) -> Box<dyn UnitImpl> {67 match self {51 TimeUnit::Second => 3,52 _ => 1,68 TimeUnit::MicroSecond => Box::new(Dispatcher::<microsecond>::new()),69 TimeUnit::MilliSecond => Box::new(Dispatcher::<millisecond>::new()),70 TimeUnit::Second => Box::new(Dispatcher::<second>::new()),71 TimeUnit::Minute => Box::new(Dispatcher::<minute>::new()),72 TimeUnit::Hour => Box::new(Dispatcher::<hour>::new()),73 }74 }7576 /// A short abbreviation like `s`, `ms`, or `µs`.77 pub fn short_name(self) -> &'static str {78 self.dispatch().short_name()79 }8081 /// Formats the quantity as a string in the given Unit.82 pub fn format(self, value: Time, precision: usize) -> String {83 self.dispatch().format_value(value, precision)84 }85}8687/// Supported information units88#[derive(Debug, Clone, Copy, PartialEq, Eq)]
87 unmodified lines
176 assert_eq!("µs", TimeUnit::MicroSecond.short_name());177 assert_eq!("min", TimeUnit::Minute.short_name());178 assert_eq!("h", TimeUnit::Hour.short_name());179}150151// Note - the values are rounded when formatted.152#[test]153fn test_unit_format() {154 use crate::quantity::FormatQuantity;155156 let value = Time::new::<second>(123.456789);157 assert_eq!("123.457", value.format_value(TimeUnit::Second));158 assert_eq!("123456.8", value.format_value(TimeUnit::MilliSecond));159160 assert_eq!(161 "1234.6",162 Time::new::<second>(0.00123456).format_value(TimeUnit::MicroSecond)163 );164 assert_eq!("2.1", value.format_value(TimeUnit::Minute));165 assert_eq!("0.0", value.format_value(TimeUnit::Hour));166}
modified:src/options.rs+1 added-2 removed
7 unmodified lines
8use clap::ArgMatches;910use crate::command::Commands;11use crate::error::OptionsError;12use crate::quantity::{second, Time};13use crate::util::units::TimeUnit;12use crate::quantity::{second, Time, TimeUnit};1314use anyhow::Result;1516#[cfg(not(windows))]
560 unmodified lines