Use uom
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 9ec7a9c · Browse files · 15 files·+441 added−425 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
15 files+441 added−425 removed
- other:+441 added−425 removed
Provenance
- Commit
641451a- Tree
8b8f765- Author
David Peter <sharkdp@users.noreply.github.com>- Committer
David Peter <mail@david-peter.de>- Parent
9ec7a9c
15 files changed+441 added−425 removed
modified:src/benchmark/benchmark_result.rs+2 added-2 removed
1 use std::collections::BTreeMap;2 3 use serde::Serialize;4 5-use crate::benchmark::{measurement::Measurements, quantity::Second};5+use crate::benchmark::{measurement::Measurements, quantity::Time};6 7 /// Parameter value and whether it was used in the command line template8 #[derive(Debug, Default, Clone, Serialize, PartialEq)]9 pub struct Parameter {26 unmodified lines36 }37 38 impl BenchmarkResult {39 /// The average wall clock time40- pub fn mean_wall_clock_time(&self) -> Second {40+ pub fn mean_wall_clock_time(&self) -> Time {41 self.measurements.time_wall_clock_mean()42 }43 44 /// The full command line of the program that is being benchmarked, possibly including a list of19 unmodified linesmodified:src/benchmark/executor.rs+18 added-14 removed
2 unmodified lines3 use std::process::ExitStatus;4 5 use crate::benchmark::measurement::Measurement;6 use crate::benchmark::measurement::Measurements;7-use crate::benchmark::quantity::Byte;8-use crate::benchmark::quantity::Second;7+use crate::benchmark::quantity::Information;8+use crate::benchmark::quantity::InformationQuantity;9+use crate::benchmark::quantity::{Time, TimeQuantity};10 use crate::command::Command;11 use crate::options::{12 CmdFailureAction, CommandInputPolicy, CommandOutputPolicy, Options, OutputStyleOption, Shell,13 };158 unmodified lines172 fn calibrate(&mut self) -> Result<()> {173 Ok(())174 }175 175- fn time_overhead(&self) -> Second {176- Second::zero()176+ fn time_overhead(&self) -> Time {177+ Time::zero()178 }179 }180 181 pub struct ShellExecutor<'a> {41 unmodified lines223 &command.get_command_line(),224 )?;225 226 // Subtract shell spawning time226- fn ensure_non_negative(time: Second) -> Second {227- if time < Second::zero() {228- Second::zero()227+ fn ensure_non_negative(time: Time) -> Time {228+ if time < Time::zero() {229+ Time::zero()230 } else {231 time232 }233 }76 unmodified lines310 311 Ok(())312 }313 313- fn time_overhead(&self) -> Second {314+ fn time_overhead(&self) -> Time {315 self.shell_spawning_time.as_ref().unwrap().time_wall_clock316 }317 }318 8 unmodified lines327 }328 329 fn extract_time<S: AsRef<str>>(sleep_command: S) -> Time {330 assert!(sleep_command.as_ref().starts_with("sleep "));330- Second::new(331+ Time::from_seconds(332 sleep_command333 .as_ref()334 .trim_start_matches("sleep ")335 .parse::<f64>()23 unmodified lines359 };360 361 Ok(Measurement {362 time_wall_clock: Self::extract_time(command.get_command_line()),362- time_user: Second::zero(),363- time_system: Second::zero(),364- peak_memory_usage: Byte::new(0),363+ time_user: Time::zero(),364+ time_system: Time::zero(),365+ peak_memory_usage: Information::from_bytes(0),366 exit_status,367 })368 }369 2 unmodified lines372 }373 374 fn time_overhead(&self) -> Time {375 match &self.shell {375- None => Second::zero(),376+ None => Time::zero(),377 Some(shell) => Self::extract_time(shell),378 }379 }380 }381 382 #[test]383 fn test_mock_executor_extract_time() {383- assert_eq!(MockExecutor::extract_time("sleep 0.1"), Second::new(0.1));384+ assert_eq!(385+ MockExecutor::extract_time("sleep 0.1"),386+ Time::from_seconds(0.1)387+ );388 }modified:src/benchmark/measurement.rs+22 added-15 removed
1 use std::process::ExitStatus;2 3 use serde::Serialize;4 5-use crate::benchmark::quantity::{max, mean, median, min, standard_deviation, Byte, Second};5+use crate::benchmark::quantity::{6+ max, mean, median, min, second, serialize_information, serialize_time, standard_deviation,7+ Information, Time, TimeQuantity,8+};9 use crate::outlier_detection::modified_zscores;10 use crate::util::exit_code::extract_exit_code;11 12 fn serialize_exit_status<S>(exit_status: &ExitStatus, serializer: S) -> Result<S::Ok, S::Error>9 unmodified lines22 /// Performance metric measurements and exit code for a single run23 #[derive(Debug, Clone, Default, Serialize, PartialEq)]24 pub struct Measurement {25 /// Elapsed wall clock time (real time)26+ #[serde(serialize_with = "serialize_time")]23- pub time_wall_clock: Second,27+ pub time_wall_clock: Time,28 29 /// Time spent in user mode30+ #[serde(serialize_with = "serialize_time")]26- pub time_user: Second,31+ pub time_user: Time,32 33 /// Time spent in kernel mode34+ #[serde(serialize_with = "serialize_time")]29- pub time_system: Second,35+ pub time_system: Time,36 37 /// Maximum memory usage of the process38+ #[serde(serialize_with = "serialize_information")]32- pub peak_memory_usage: Byte,39+ pub peak_memory_usage: Information,40 41 // The exit status of the process42 #[serde(rename = "exit_code", serialize_with = "serialize_exit_status")]43 pub exit_status: ExitStatus,20 unmodified lines64 pub fn push(&mut self, measurement: Measurement) {65 self.measurements.push(measurement);66 }67 61- pub fn wall_clock_times(&self) -> Vec<Second> {68+ pub fn wall_clock_times(&self) -> Vec<Time> {69 self.measurements70 .iter()71 .map(|m| m.time_wall_clock)72 .collect()73 }74 75 /// The average wall clock time69- pub fn time_wall_clock_mean(&self) -> Second {76+ pub fn time_wall_clock_mean(&self) -> Time {77 mean(&self.wall_clock_times())78 }79 80 /// The standard deviation of all wall clock times. Not available if only one run has been performed74- pub fn stddev(&self) -> Option<Second> {81+ pub fn stddev(&self) -> Option<Time> {82 let times = self.wall_clock_times();83 84 if times.len() < 2 {85 None2 unmodified lines88 }89 }90 91 /// The median wall clock time85- pub fn median(&self) -> Second {92+ pub fn median(&self) -> Time {93 median(&self.wall_clock_times())94 }95 96 /// The minimum wall clock time90- pub fn min(&self) -> Second {97+ pub fn min(&self) -> Time {98 min(&self.wall_clock_times())99 }100 101 /// The maximum wall clock time95- pub fn max(&self) -> Second {102+ pub fn max(&self) -> Time {103 max(&self.wall_clock_times())104 }105 106 /// The average user time100- pub fn time_user_mean(&self) -> Second {107+ pub fn time_user_mean(&self) -> Time {108 mean(109 &self110 .measurements111 .iter()2 unmodified lines114 )115 }116 117 /// The average system time111- pub fn time_system_mean(&self) -> Second {118+ pub fn time_system_mean(&self) -> Time {119 mean(120 &self121 .measurements122 .iter()1 unmodified line124 .collect::<Vec<_>>(),125 )126 }127 121- pub fn peak_memory_usage_mean(&self) -> Byte {128+ pub fn peak_memory_usage_mean(&self) -> Information {129 self.measurements130 .iter()131 .map(|m| m.peak_memory_usage)132 .max_by(|a, b| a.partial_cmp(b).unwrap()) // TODO4 unmodified lines137 modified_zscores(138 &self139 .wall_clock_times()140 .iter()134- .map(|t| t.value_in::<Second>()) // TODO141+ .map(|t| t.value_in::<second>()) // TODO142 .collect::<Vec<_>>(),143 )144 }145 4 unmodified linesmodified:src/benchmark/mod.rs+6 added-6 removed
10 unmodified lines11 12 use crate::benchmark::benchmark_result::Parameter;13 use crate::benchmark::executor::BenchmarkIteration;14 use crate::benchmark::measurement::{Measurement, Measurements};15-use crate::benchmark::quantity::{MilliSecond, Second};15+use crate::benchmark::quantity::{const_time_from_seconds, Time, TimeQuantity};16 use crate::command::Command;17 use crate::options::{18 CmdFailureAction, CommandOutputPolicy, ExecutorKind, Options, OutputStyleOption,19 };12 unmodified lines32 33 use self::executor::Executor;34 35 /// Threshold for warning about fast execution time36-pub const MIN_EXECUTION_TIME: MilliSecond = MilliSecond::new(5.);36+pub const MIN_EXECUTION_TIME: Time = const_time_from_seconds(0.005);37 38 pub struct Benchmark<'a> {39 number: usize,40 command: &'a Command<'a>,220 unmodified lines261 None262 };263 264 let preparation_result = run_preparation_command()?;265- let preparation_overhead = preparation_result.map_or(Second::zero(), |res| {265+ let preparation_overhead = preparation_result.map_or(Time::zero(), |res| {266 res.time_wall_clock + self.executor.time_overhead()267 });268 269 // Initial timing run20 unmodified lines290 );291 }292 293 let conclusion_result = run_conclusion_command()?;294- let conclusion_overhead = conclusion_result.map_or(Second::zero(), |res| {294+ let conclusion_overhead = conclusion_result.map_or(Time::zero(), |res| {295 res.time_wall_clock + self.executor.time_overhead()296 });297 298 // Determine number of benchmark runs1 unmodified line300 / (result.time_wall_clock301 + self.executor.time_overhead()302 + preparation_overhead303 + conclusion_overhead))304- .get::<ratio>() as u64;304+ .get::<quantity::ratio>() as u64;305 306 let count = {307 let min = cmp::max(runs_in_min_time, self.options.run_bounds.min);308 122 unmodified lines431 if matches!(self.options.executor_kind, ExecutorKind::Shell(_))432 && measurements433 .wall_clock_times()434 .iter()435- .any(|&t| t < MIN_EXECUTION_TIME.convert_to::<Second>())435+ .any(|&t| t < MIN_EXECUTION_TIME)436 {437 warnings.push(Warnings::FastExecutionTime);438 }439 63 unmodified linesmodified:src/benchmark/quantity.rs+130 added-198 removed
1-use std::{2- fmt::{self, Display, Formatter},3- ops::{Add, Div, Sub},4-};1+use core::f64;2+use std::marker::PhantomData;3 6-use serde::{ser::SerializeStruct, Serialize, Serializer};4+use serde::ser::SerializeStruct;5+use serde::Serializer;6+use uom::{si, Conversion};7 8-pub trait IsQuantity {9- type Value;8+pub use uom::si::information::{byte, kibibyte};9+pub use uom::si::ratio::ratio;10+pub use uom::si::time::{microsecond, millisecond, nanosecond, second};11 11- const IS_TIME: bool;12- const METRIC_PREFIX_TIME: i32;13- const IS_INFORMATION: bool;14- const BINARY_PREFIX_INFORMATION: i32;12+pub use si::f64::Ratio;13+pub use si::f64::Time;14+pub use si::u64::Information;15 16- fn unsafe_from(value: Self::Value) -> Self;17-}18-19-#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, PartialOrd)] // TODO: check partialord20-pub struct Quantity<21- Value,22- const IS_TIME: bool,23- const METRIC_PREFIX_TIME: i32,24- const IS_INFORMATION: bool,25- const BINARY_PREFIX_INFORMATION: i32,26->(Value);27-28-impl<29- Value,30- const IS_TIME: bool,31- const METRIC_PREFIX_TIME: i32,32- const IS_INFORMATION: bool,33- const BINARY_PREFIX_INFORMATION: i32,34- > IsQuantity35- for Quantity<Value, IS_TIME, METRIC_PREFIX_TIME, IS_INFORMATION, BINARY_PREFIX_INFORMATION>36-{37- type Value = Value;38- const IS_TIME: bool = IS_TIME;39- const METRIC_PREFIX_TIME: i32 = METRIC_PREFIX_TIME;40- const IS_INFORMATION: bool = IS_INFORMATION;41- const BINARY_PREFIX_INFORMATION: i32 = BINARY_PREFIX_INFORMATION;42-43- fn unsafe_from(value: Self::Value) -> Self {44- Self(value)16+pub trait TimeQuantity {17+ fn zero() -> Time {18+ Time::new::<second>(0.0)19 }46-}20 48-type Time<const PREFIX: i32> = Quantity<f64, true, PREFIX, false, 0>;49-type Information<const PREFIX: i32> = Quantity<u64, false, 0, true, PREFIX>;50-51-pub type Second = Time<0>;52-pub type MilliSecond = Time<-3>;53-pub type MicroSecond = Time<-6>;54-55-pub type Byte = Information<0>;56-pub type KibiByte = Information<10>;57-pub type MebiByte = Information<20>;58-pub type GibiByte = Information<30>;59-pub type TebiByte = Information<40>;60-61-impl<62- Value: Copy + Default,63- const IS_TIME: bool,64- const METRIC_PREFIX_TIME: i32,65- const IS_INFORMATION: bool,66- const BINARY_PREFIX_INFORMATION: i32,67- > Quantity<Value, IS_TIME, METRIC_PREFIX_TIME, IS_INFORMATION, BINARY_PREFIX_INFORMATION>68-{69- pub const fn new(value: Value) -> Self {70- Self(value)21+ fn from_seconds(value: f64) -> Time {22+ Time::new::<second>(value)23 }24 73- pub fn zero() -> Self {74- Self::new(Value::default())25+ fn from_milliseconds(value: f64) -> Time {26+ Time::new::<millisecond>(value)27 }28 77- pub fn value_in<TargetUnit: IsQuantity>(&self) -> Value {78- const {79- assert!(IS_TIME == TargetUnit::IS_TIME);80- assert!(METRIC_PREFIX_TIME == TargetUnit::METRIC_PREFIX_TIME);81- assert!(IS_INFORMATION == TargetUnit::IS_INFORMATION);82- assert!(BINARY_PREFIX_INFORMATION == TargetUnit::BINARY_PREFIX_INFORMATION);83- }84-85- self.029+ fn from_microseconds(value: f64) -> Time {30+ Time::new::<microsecond>(value)31 }32 88- const fn unit_name(&self) -> &'static str {89- match (IS_TIME, IS_INFORMATION) {90- (true, false) => match METRIC_PREFIX_TIME {91- -6 => "µs",92- -3 => "ms",93- 0 => "s",94- _ => unreachable!(),95- },96- (false, true) => match BINARY_PREFIX_INFORMATION {97- 0 => "B",98- 10 => "KiB",99- 20 => "MiB",100- 30 => "GiB",101- 40 => "TiB",102- _ => unreachable!(),103- },104- _ => unreachable!(),105- }33+ fn from_nanoseconds(value: f64) -> Time {34+ Time::new::<nanosecond>(value)35 }36 108- const fn unit_name_long(&self) -> &'static str {109- match (IS_TIME, IS_INFORMATION) {110- (true, false) => match METRIC_PREFIX_TIME {111- -6 => "microsecond",112- -3 => "millisecond",113- 0 => "second",114- _ => unreachable!(),115- },116- (false, true) => match BINARY_PREFIX_INFORMATION {117- 0 => "byte",118- 10 => "kibibyte",119- 20 => "mebibyte",120- 30 => "gibibyte",121- 40 => "tebibyte",122- _ => unreachable!(),123- },124- _ => unreachable!(),125- }126- }127-}37+ // fn square(&self) -> Time;38 129-impl<const METRIC_PREFIX_TIME: i32> Time<METRIC_PREFIX_TIME> {130- pub fn convert_to<TargetUnit: IsQuantity<Value = f64>>(&self) -> TargetUnit {131- let factor = 10_f64.powi(METRIC_PREFIX_TIME - TargetUnit::METRIC_PREFIX_TIME);39+ fn value_in<U>(&self) -> f6440+ where41+ U: si::time::Unit + Conversion<f64, T = f64>;42 133- TargetUnit::unsafe_from(self.0 * factor)134- }43+ fn to_string<U>(&self, u: U) -> String44+ where45+ U: si::time::Unit + Conversion<f64, T = f64>;46 }47 137-impl<const METRIC_PREFIX_TIME: i32> Add<Time<METRIC_PREFIX_TIME>> for Time<METRIC_PREFIX_TIME> {138- type Output = Time<METRIC_PREFIX_TIME>;48+impl TimeQuantity for Time {49+ fn value_in<U>(&self) -> f6450+ where51+ U: si::time::Unit + Conversion<f64, T = f64>,52+ {53+ self.get::<U>()54+ }55 140- fn add(self, rhs: Time<METRIC_PREFIX_TIME>) -> Self::Output {141- Time::new(self.0 + rhs.0)56+ fn to_string<U>(&self, u: U) -> String57+ where58+ U: si::time::Unit + Conversion<f64, T = f64>,59+ {60+ format!(61+ "{:.3}",62+ self.into_format_args(u, uom::fmt::DisplayStyle::Abbreviation)63+ )64 }65 }66 145-impl<const METRIC_PREFIX_TIME: i32> Sub<Time<METRIC_PREFIX_TIME>> for Time<METRIC_PREFIX_TIME> {146- type Output = Time<METRIC_PREFIX_TIME>;147-148- fn sub(self, rhs: Time<METRIC_PREFIX_TIME>) -> Self::Output {149- Time::new(self.0 - rhs.0)67+pub const fn const_time_from_seconds(value: f64) -> Time {68+ // Quantity::new in uom is not yet const: https://docs.rs/uom/0.36.0/uom/si/struct.Quantity.html69+ Time {70+ dimension: PhantomData,71+ units: PhantomData,72+ value,73 }74 }75 153-impl<const METRIC_PREFIX_TIME: i32> Div<Time<METRIC_PREFIX_TIME>> for Time<METRIC_PREFIX_TIME> {154- type Output = f64;76+pub trait InformationQuantity {77+ fn zero() -> Information {78+ Information::new::<byte>(0)79+ }80 156- fn div(self, rhs: Time<METRIC_PREFIX_TIME>) -> Self::Output {157- self.0 / rhs.081+ fn from_bytes(value: u64) -> Information {82+ Information::new::<byte>(value)83 }159-}84 161-impl<const METRIC_PREFIX_TIME: i32> Display for Time<METRIC_PREFIX_TIME> {162- fn fmt(&self, f: &mut Formatter) -> fmt::Result {163- let prefix = match METRIC_PREFIX_TIME {164- -6 => "µ",165- -3 => "m",166- 0 => "s",167- _ => unreachable!(),168- };169- write!(f, "{} {}s", self.0, prefix)85+ fn from_kibibytes(value: u64) -> Information {86+ Information::new::<kibibyte>(value)87 }88+89+ fn value_in<U>(&self) -> u6490+ where91+ U: si::information::Unit + Conversion<u64, T = uom::num_rational::Ratio<u64>>;92+93+ fn to_string<U>(&self, u: U) -> String94+ where95+ U: si::information::Unit + Conversion<u64, T = uom::num_rational::Ratio<u64>>;96 }97 173-impl<const BINARY_PREFIX_INFORMATION: i32> Display for Information<BINARY_PREFIX_INFORMATION> {174- fn fmt(&self, f: &mut Formatter) -> fmt::Result {175- let prefix = match BINARY_PREFIX_INFORMATION {176- 0 => "",177- 10 => "Ki",178- 20 => "Mi",179- 30 => "Gi",180- 40 => "Ti",181- _ => unreachable!(),182- };183- write!(f, "{} {}B", self.0, prefix)98+impl InformationQuantity for Information {99+ fn value_in<U>(&self) -> u64100+ where101+ U: si::information::Unit + Conversion<u64, T = uom::num_rational::Ratio<u64>>,102+ {103+ self.get::<U>()104 }185-}105 187-impl<188- Value: Copy + Default + Serialize,189- const IS_TIME: bool,190- const METRIC_PREFIX_TIME: i32,191- const IS_INFORMATION: bool,192- const BINARY_PREFIX_INFORMATION: i32,193- > Serialize194- for Quantity<Value, IS_TIME, METRIC_PREFIX_TIME, IS_INFORMATION, BINARY_PREFIX_INFORMATION>195-{196- fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>106+ fn to_string<U>(&self, u: U) -> String107 where198- S: Serializer,108+ U: si::information::Unit + Conversion<u64, T = uom::num_rational::Ratio<u64>>,109 {200- let mut state = serializer.serialize_struct("Quantity", 2)?;201- state.serialize_field("value", &self.0)?;202- state.serialize_field("unit", self.unit_name())?;203- state.serialize_field("unit_long", self.unit_name_long())?;204- state.end()110+ format!(111+ "{}",112+ self.into_format_args(u, uom::fmt::DisplayStyle::Abbreviation)113+ )114 }115 }116 117+pub fn serialize_time<S>(t: &Time, s: S) -> Result<S::Ok, S::Error>118+where119+ S: Serializer,120+{121+ let mut state = s.serialize_struct("Time", 3)?;122+ state.serialize_field("value", &t.value)?;123+ state.serialize_field("unit", "second")?;124+ state.end()125+}126+127+pub fn serialize_information<S>(i: &Information, s: S) -> Result<S::Ok, S::Error>128+where129+ S: Serializer,130+{131+ let mut state = s.serialize_struct("Information", 3)?;132+ state.serialize_field("value", &i.value)?;133+ state.serialize_field("unit", "byte")?;134+ state.end()135+}136+137 macro_rules! quantity_fn {138 ($name:ident, $unwrapped_values:ident, $body:expr) => {210- pub fn $name<211- const IS_TIME: bool,212- const METRIC_PREFIX_TIME: i32,213- const IS_INFORMATION: bool,214- const BINARY_PREFIX_INFORMATION: i32,215- >(216- values: &[Quantity<217- f64,218- IS_TIME,219- METRIC_PREFIX_TIME,220- IS_INFORMATION,221- BINARY_PREFIX_INFORMATION,222- >],223- ) -> Quantity<f64, IS_TIME, METRIC_PREFIX_TIME, IS_INFORMATION, BINARY_PREFIX_INFORMATION> {224- let $unwrapped_values: Vec<f64> = values.iter().map(|v| v.0).collect();139+ pub fn $name(values: &[Time]) -> Time {140+ let $unwrapped_values: Vec<_> = values.iter().map(|q| q.value_in::<second>()).collect();141 let result_value = $body;226- Quantity::new(result_value)142+143+ Time::new::<second>(result_value)144 }145 };146 }147 6 unmodified lines154 statistical::standard_deviation(&values, Some(mean_value))155 });156 157 #[test]241-fn test_quantity() {242- let time = MilliSecond::new(123.4);243- assert_eq!(time.value_in::<MilliSecond>(), 123.4);158+fn test_time() {159+ let time = Time::from_milliseconds(123.4);160+ assert_eq!(time.value_in::<millisecond>(), 123.4);161 245- let time_s = time.convert_to::<Second>();246- approx::assert_relative_eq!(time_s.value_in::<Second>(), 0.1234);162+ let time_s = time.value_in::<second>();163+ approx::assert_relative_eq!(time_s, 0.1234);164 248- let time_us = time.convert_to::<MicroSecond>();249- approx::assert_relative_eq!(time_us.value_in::<MicroSecond>(), 123400.0);165+ let time_us = time.value_in::<microsecond>();166+ approx::assert_relative_eq!(time_us, 123400.0);167 }168 169 #[test]170+fn test_information() {171+ let information = Information::from_kibibytes(8);172+ assert_eq!(information.value_in::<byte>(), 8192);173+174+ let information_kib = information.value_in::<kibibyte>();175+ assert_eq!(information_kib, 8);176+}177+178+#[test]179 fn test_format() {254- let time = MilliSecond::new(123.4);255- assert_eq!(time.to_string(), "123.4 ms");180+ let time = Time::from_milliseconds(123.4);181+ assert_eq!(time.to_string(second), "0.123 s");182+ assert_eq!(time.to_string(millisecond), "123.400 ms");183+ assert_eq!(time.to_string(microsecond), "123400.000 µs");184 257- let peak_memory_usage = KibiByte::new(8);258- assert_eq!(peak_memory_usage.to_string(), "8 KiB");185+ let peak_memory_usage = Information::from_kibibytes(8);186+ assert_eq!(peak_memory_usage.to_string(byte), "8192 B");187+ assert_eq!(peak_memory_usage.to_string(kibibyte), "8 KiB");188 }189 190 #[test]191 fn test_mean() {263- let values = vec![MilliSecond::new(123.4), MilliSecond::new(234.5)];192+ let values = vec![193+ Time::from_milliseconds(123.4),194+ Time::from_milliseconds(234.5),195+ ];196 let result = mean(&values);265- assert_eq!(result.to_string(), "178.95 ms");197+ assert_eq!(result.to_string(millisecond), "178.950 ms");198 }modified:src/benchmark/relative_speed.rs+15 added-12 removed
1 use std::cmp::Ordering;2 3 use super::benchmark_result::BenchmarkResult;4-use crate::{benchmark::quantity::Second, options::SortOrder};4+use crate::{5+ benchmark::quantity::{self, Ratio, Time, TimeQuantity},6+ options::SortOrder,7+};8 9 #[derive(Debug)]10 pub struct BenchmarkResultWithRelativeSpeed<'a> {11 pub result: &'a BenchmarkResult,42 unmodified lines54 // Separate benchmarks can have identical names and measurements.55 let is_reference = std::ptr::eq(result, reference);56 let relative_ordering = compare_mean_time(result, reference);57 55- if result.mean_wall_clock_time() == Second::zero()56- || reference.mean_wall_clock_time() == Second::zero()58+ if result.mean_wall_clock_time() == Time::zero()59+ || reference.mean_wall_clock_time() == Time::zero()60 {61 return BenchmarkResultWithRelativeSpeed {62 result,63 relative_speed: if is_reference { 1.0 } else { f64::INFINITY },4 unmodified lines68 }69 70 let ratio = match relative_ordering {71 Ordering::Less => reference.mean_wall_clock_time() / result.mean_wall_clock_time(),69- Ordering::Equal => 1.0,72+ Ordering::Equal => Ratio::new::<quantity::ratio>(1.0),73 Ordering::Greater => {74 result.mean_wall_clock_time() / reference.mean_wall_clock_time()75 }76 };39 unmodified lines116 results: &'a [BenchmarkResult],117 reference: &'a BenchmarkResult,118 sort_order: SortOrder,119 ) -> Option<Vec<BenchmarkResultWithRelativeSpeed<'a>>> {117- if fastest_of(results).mean_wall_clock_time() == Second::zero()118- || reference.mean_wall_clock_time() == Second::zero()120+ if fastest_of(results).mean_wall_clock_time() == Time::zero()121+ || reference.mean_wall_clock_time() == Time::zero()122 {123 return None;124 }125 5 unmodified lines131 sort_order: SortOrder,132 ) -> Option<Vec<BenchmarkResultWithRelativeSpeed<'_>>> {133 let fastest = fastest_of(results);134 132- if fastest.mean_wall_clock_time() == Second::zero() {135+ if fastest.mean_wall_clock_time() == Time::zero() {136 return None;137 }138 139 Some(compute_relative_speeds(results, fastest, sort_order))14 unmodified lines154 use std::{collections::BTreeMap, process::ExitStatus};155 156 use crate::benchmark::{157 measurement::{Measurement, Measurements},155- quantity::Byte,158+ quantity::{Information, InformationQuantity},159 };160 161 BenchmarkResult {162 command: name.into(),163 measurements: Measurements {164 measurements: vec![Measurement {162- time_wall_clock: Second::new(mean),163- time_user: Second::new(mean),164- time_system: Second::zero(),165- peak_memory_usage: Byte::new(1024),165+ time_wall_clock: Time::from_seconds(mean),166+ time_user: Time::from_seconds(mean),167+ time_system: Time::zero(),168+ peak_memory_usage: Information::from_bytes(1024),169 exit_status: ExitStatus::default(),170 }],171 },172 parameters: BTreeMap::new(),67 unmodified linesmodified:src/benchmark/scheduler.rs+16 added-32 removed
206 unmodified lines207 - command: sleep 0.123208 measurements:209 - time_wall_clock:210 value: 0.123211- unit: s212- unit_long: second211+ unit: second212 time_user:213 value: 0215- unit: s216- unit_long: second214+ unit: second215 time_system:216 value: 0219- unit: s220- unit_long: second217+ unit: second218 peak_memory_usage:219 value: 0223- unit: B224- unit_long: byte220+ unit: byte221 exit_code: 0222 - time_wall_clock:223 value: 0.123228- unit: s229- unit_long: second224+ unit: second225 time_user:226 value: 0232- unit: s233- unit_long: second227+ unit: second228 time_system:229 value: 0236- unit: s237- unit_long: second230+ unit: second231 peak_memory_usage:232 value: 0240- unit: B241- unit_long: byte233+ unit: byte234 exit_code: 0235 - command: sleep 0.456236 measurements:237 - time_wall_clock:238 value: 0.456247- unit: s248- unit_long: second239+ unit: second240 time_user:241 value: 0251- unit: s252- unit_long: second242+ unit: second243 time_system:244 value: 0255- unit: s256- unit_long: second245+ unit: second246 peak_memory_usage:247 value: 0259- unit: B260- unit_long: byte248+ unit: byte249 exit_code: 0250 - time_wall_clock:251 value: 0.456264- unit: s265- unit_long: second252+ unit: second253 time_user:254 value: 0268- unit: s269- unit_long: second255+ unit: second256 time_system:257 value: 0272- unit: s273- unit_long: second258+ unit: second259 peak_memory_usage:260 value: 0276- unit: B277- unit_long: byte261+ unit: byte262 exit_code: 0263 "#);264 265 Ok(())1 unmodified linemodified:src/export/csv.rs+27 added-27 removed
2 unmodified lines3 use csv::WriterBuilder;4 5 use super::Exporter;6 use crate::benchmark::benchmark_result::BenchmarkResult;7-use crate::benchmark::quantity::Second;7+use crate::benchmark::quantity::{second, TimeQuantity};8 use crate::options::SortOrder;9 use crate::quantity::{FormatQuantity, TimeUnit};10 11 use anyhow::Result;40 unmodified lines52 res.measurements.time_system_mean(),53 res.measurements.min(),54 res.measurements.max(),55 ] {56- fields.push(Cow::Owned(f.value_in::<Second>().to_string().into_bytes()))56+ fields.push(Cow::Owned(f.value_in::<second>().to_string().into_bytes()))57 }58 for v in res.parameters.values() {59 fields.push(Cow::Borrowed(v.value.as_bytes()))60 }7 unmodified lines68 #[test]69 fn test_csv() {70 use crate::benchmark::benchmark_result::Parameter;71 use crate::benchmark::measurement::{Measurement, Measurements};72- use crate::benchmark::quantity::{Byte, Second};72+ use crate::benchmark::quantity::{Information, InformationQuantity, Time, TimeQuantity};73 74 use std::collections::BTreeMap;75 use std::process::ExitStatus;76 3 unmodified lines80 BenchmarkResult {81 command: String::from("command_a"),82 measurements: Measurements::new(vec![83 Measurement {84- time_wall_clock: Second::new(7.0),85- time_user: Second::new(7.0),86- time_system: Second::zero(),87- peak_memory_usage: Byte::new(1024),84+ time_wall_clock: Time::from_seconds(7.0),85+ time_user: Time::from_seconds(7.0),86+ time_system: Time::zero(),87+ peak_memory_usage: Information::from_bytes(1024),88 exit_status: ExitStatus::default(),89 },90 Measurement {91- time_wall_clock: Second::new(8.0),92- time_user: Second::new(8.0),93- time_system: Second::zero(),94- peak_memory_usage: Byte::new(1024),91+ time_wall_clock: Time::from_seconds(8.0),92+ time_user: Time::from_seconds(8.0),93+ time_system: Time::zero(),94+ peak_memory_usage: Information::from_bytes(1024),95 exit_status: ExitStatus::default(),96 },97 Measurement {98- time_wall_clock: Second::new(12.0),99- time_user: Second::new(12.0),100- time_system: Second::zero(),101- peak_memory_usage: Byte::new(1024),98+ time_wall_clock: Time::from_seconds(12.0),99+ time_user: Time::from_seconds(12.0),100+ time_system: Time::zero(),101+ peak_memory_usage: Information::from_bytes(1024),102 exit_status: ExitStatus::default(),103 },104 ]),105 parameters: {18 unmodified lines124 BenchmarkResult {125 command: String::from("command_b"),126 measurements: Measurements::new(vec![127 Measurement {128- time_wall_clock: Second::new(17.0),129- time_user: Second::new(17.0),130- time_system: Second::zero(),131- peak_memory_usage: Byte::new(1024),128+ time_wall_clock: Time::from_seconds(17.0),129+ time_user: Time::from_seconds(17.0),130+ time_system: Time::zero(),131+ peak_memory_usage: Information::from_bytes(1024),132 exit_status: ExitStatus::default(),133 },134 Measurement {135- time_wall_clock: Second::new(18.0),136- time_user: Second::new(18.0),137- time_system: Second::zero(),138- peak_memory_usage: Byte::new(1024),135+ time_wall_clock: Time::from_seconds(18.0),136+ time_user: Time::from_seconds(18.0),137+ time_system: Time::zero(),138+ peak_memory_usage: Information::from_bytes(1024),139 exit_status: ExitStatus::default(),140 },141 Measurement {142- time_wall_clock: Second::new(19.0),143- time_user: Second::new(19.0),144- time_system: Second::zero(),145- peak_memory_usage: Byte::new(1024),142+ time_wall_clock: Time::from_seconds(19.0),143+ time_user: Time::from_seconds(19.0),144+ time_system: Time::zero(),145+ peak_memory_usage: Information::from_bytes(1024),146 exit_status: ExitStatus::default(),147 },148 ]),149 parameters: {33 unmodified linesmodified:src/export/tests.rs+97 added-97 removed
1 use super::Exporter;2 use crate::benchmark::benchmark_result::BenchmarkResult;3 use crate::benchmark::measurement::{Measurement, Measurements};4-use crate::benchmark::quantity::{Byte, Second};4+use crate::benchmark::quantity::{Information, InformationQuantity, Time, TimeQuantity};5 use crate::export::asciidoc::AsciidocExporter;6 use crate::export::orgmode::OrgmodeExporter;7 use crate::quantity::{byte, second, Information, Time, TimeUnit, Zero};8 use crate::{export::markdown::MarkdownExporter, options::SortOrder};21 unmodified lines30 BenchmarkResult {31 command: String::from("sleep 0.1"),32 measurements: Measurements::new(vec![33 Measurement {34- time_wall_clock: Second::new(0.09),35- time_user: Second::new(0.09),36- time_system: Second::zero(),37- peak_memory_usage: Byte::new(1024),34+ time_wall_clock: Time::from_seconds(0.09),35+ time_user: Time::from_seconds(0.09),36+ time_system: Time::zero(),37+ peak_memory_usage: Information::from_bytes(1024),38 exit_status: ExitStatus::default(),39 },40 Measurement {41- time_wall_clock: Second::new(0.10),42- time_user: Second::new(0.10),43- time_system: Second::zero(),44- peak_memory_usage: Byte::new(1024),41+ time_wall_clock: Time::from_seconds(0.10),42+ time_user: Time::from_seconds(0.10),43+ time_system: Time::zero(),44+ peak_memory_usage: Information::from_bytes(1024),45 exit_status: ExitStatus::default(),46 },47 Measurement {48- time_wall_clock: Second::new(0.14),49- time_user: Second::new(0.14),50- time_system: Second::zero(),51- peak_memory_usage: Byte::new(1024),48+ time_wall_clock: Time::from_seconds(0.14),49+ time_user: Time::from_seconds(0.14),50+ time_system: Time::zero(),51+ peak_memory_usage: Information::from_bytes(1024),52 exit_status: ExitStatus::default(),53 },54 ]),55 parameters: BTreeMap::new(),1 unmodified line57 BenchmarkResult {58 command: String::from("sleep 2"),59 measurements: Measurements::new(vec![60 Measurement {61- time_wall_clock: Second::new(2.0),62- time_user: Second::new(2.0),63- time_system: Second::zero(),64- peak_memory_usage: Byte::new(1024),61+ time_wall_clock: Time::from_seconds(2.0),62+ time_user: Time::from_seconds(2.0),63+ time_system: Time::zero(),64+ peak_memory_usage: Information::from_bytes(1024),65 exit_status: ExitStatus::default(),66 },67 Measurement {68- time_wall_clock: Second::new(3.0),69- time_user: Second::new(3.0),70- time_system: Second::zero(),71- peak_memory_usage: Byte::new(1024),68+ time_wall_clock: Time::from_seconds(3.0),69+ time_user: Time::from_seconds(3.0),70+ time_system: Time::zero(),71+ peak_memory_usage: Information::from_bytes(1024),72 exit_status: ExitStatus::default(),73 },74 Measurement {75- time_wall_clock: Second::new(4.0),76- time_user: Second::new(4.0),77- time_system: Second::zero(),78- peak_memory_usage: Byte::new(1024),75+ time_wall_clock: Time::from_seconds(4.0),76+ time_user: Time::from_seconds(4.0),77+ time_system: Time::zero(),78+ peak_memory_usage: Information::from_bytes(1024),79 exit_status: ExitStatus::default(),80 },81 ]),82 parameters: BTreeMap::new(),46 unmodified lines129 BenchmarkResult {130 command: String::from("sleep 2"),131 measurements: Measurements::new(vec![132 Measurement {133- time_wall_clock: Second::new(2.1),134- time_user: Second::new(2.1),135- time_system: Second::zero(),136- peak_memory_usage: Byte::new(1024),133+ time_wall_clock: Time::from_seconds(2.1),134+ time_user: Time::from_seconds(2.1),135+ time_system: Time::zero(),136+ peak_memory_usage: Information::from_bytes(1024),137 exit_status: ExitStatus::default(),138 },139 Measurement {140- time_wall_clock: Second::new(2.2),141- time_user: Second::new(2.2),142- time_system: Second::zero(),143- peak_memory_usage: Byte::new(1024),140+ time_wall_clock: Time::from_seconds(2.2),141+ time_user: Time::from_seconds(2.2),142+ time_system: Time::zero(),143+ peak_memory_usage: Information::from_bytes(1024),144 exit_status: ExitStatus::default(),145 },146 Measurement {147- time_wall_clock: Second::new(2.3),148- time_user: Second::new(2.3),149- time_system: Second::zero(),150- peak_memory_usage: Byte::new(1024),147+ time_wall_clock: Time::from_seconds(2.3),148+ time_user: Time::from_seconds(2.3),149+ time_system: Time::zero(),150+ peak_memory_usage: Information::from_bytes(1024),151 exit_status: ExitStatus::default(),152 },153 ]),154 parameters: BTreeMap::new(),1 unmodified line156 BenchmarkResult {157 command: String::from("sleep 0.1"),158 measurements: Measurements::new(vec![159 Measurement {160- time_wall_clock: Second::new(0.1),161- time_user: Second::new(0.1),162- time_system: Second::zero(),163- peak_memory_usage: Byte::new(1024),160+ time_wall_clock: Time::from_seconds(0.1),161+ time_user: Time::from_seconds(0.1),162+ time_system: Time::zero(),163+ peak_memory_usage: Information::from_bytes(1024),164 exit_status: ExitStatus::default(),165 },166 Measurement {167- time_wall_clock: Second::new(0.2),168- time_user: Second::new(0.2),169- time_system: Second::zero(),170- peak_memory_usage: Byte::new(1024),167+ time_wall_clock: Time::from_seconds(0.2),168+ time_user: Time::from_seconds(0.2),169+ time_system: Time::zero(),170+ peak_memory_usage: Information::from_bytes(1024),171 exit_status: ExitStatus::default(),172 },173 Measurement {174- time_wall_clock: Second::new(0.3),175- time_user: Second::new(0.3),176- time_system: Second::zero(),177- peak_memory_usage: Byte::new(1024),174+ time_wall_clock: Time::from_seconds(0.3),175+ time_user: Time::from_seconds(0.3),176+ time_system: Time::zero(),177+ peak_memory_usage: Information::from_bytes(1024),178 exit_status: ExitStatus::default(),179 },180 ]),181 parameters: BTreeMap::new(),46 unmodified lines228 BenchmarkResult {229 command: String::from("sleep 2"),230 measurements: Measurements::new(vec![231 Measurement {232- time_wall_clock: Second::new(2.1),233- time_user: Second::new(2.1),234- time_system: Second::zero(),235- peak_memory_usage: Byte::new(1024),232+ time_wall_clock: Time::from_seconds(2.1),233+ time_user: Time::from_seconds(2.1),234+ time_system: Time::zero(),235+ peak_memory_usage: Information::from_bytes(1024),236 exit_status: ExitStatus::default(),237 },238 Measurement {239- time_wall_clock: Second::new(2.2),240- time_user: Second::new(2.2),241- time_system: Second::zero(),242- peak_memory_usage: Byte::new(1024),239+ time_wall_clock: Time::from_seconds(2.2),240+ time_user: Time::from_seconds(2.2),241+ time_system: Time::zero(),242+ peak_memory_usage: Information::from_bytes(1024),243 exit_status: ExitStatus::default(),244 },245 Measurement {246- time_wall_clock: Second::new(2.3),247- time_user: Second::new(2.3),248- time_system: Second::zero(),249- peak_memory_usage: Byte::new(1024),246+ time_wall_clock: Time::from_seconds(2.3),247+ time_user: Time::from_seconds(2.3),248+ time_system: Time::zero(),249+ peak_memory_usage: Information::from_bytes(1024),250 exit_status: ExitStatus::default(),251 },252 ]),253 parameters: BTreeMap::new(),1 unmodified line255 BenchmarkResult {256 command: String::from("sleep 0.1"),257 measurements: Measurements::new(vec![258 Measurement {259- time_wall_clock: Second::new(0.1),260- time_user: Second::new(0.1),261- time_system: Second::zero(),262- peak_memory_usage: Byte::new(1024),259+ time_wall_clock: Time::from_seconds(0.1),260+ time_user: Time::from_seconds(0.1),261+ time_system: Time::zero(),262+ peak_memory_usage: Information::from_bytes(1024),263 exit_status: ExitStatus::default(),264 },265 Measurement {266- time_wall_clock: Second::new(0.2),267- time_user: Second::new(0.2),268- time_system: Second::zero(),269- peak_memory_usage: Byte::new(1024),266+ time_wall_clock: Time::from_seconds(0.2),267+ time_user: Time::from_seconds(0.2),268+ time_system: Time::zero(),269+ peak_memory_usage: Information::from_bytes(1024),270 exit_status: ExitStatus::default(),271 },272 Measurement {273- time_wall_clock: Second::new(0.3),274- time_user: Second::new(0.3),275- time_system: Second::zero(),276- peak_memory_usage: Byte::new(1024),273+ time_wall_clock: Time::from_seconds(0.3),274+ time_user: Time::from_seconds(0.3),275+ time_system: Time::zero(),276+ peak_memory_usage: Information::from_bytes(1024),277 exit_status: ExitStatus::default(),278 },279 ]),280 parameters: BTreeMap::new(),45 unmodified lines326 BenchmarkResult {327 command: String::from("sleep 2"),328 measurements: Measurements::new(vec![329 Measurement {330- time_wall_clock: Second::new(2.01),331- time_user: Second::new(2.01),332- time_system: Second::zero(),333- peak_memory_usage: Byte::new(1024),330+ time_wall_clock: Time::from_seconds(2.01),331+ time_user: Time::from_seconds(2.01),332+ time_system: Time::zero(),333+ peak_memory_usage: Information::from_bytes(1024),334 exit_status: ExitStatus::default(),335 },336 Measurement {337- time_wall_clock: Second::new(2.02),338- time_user: Second::new(2.02),339- time_system: Second::zero(),340- peak_memory_usage: Byte::new(1024),337+ time_wall_clock: Time::from_seconds(2.02),338+ time_user: Time::from_seconds(2.02),339+ time_system: Time::zero(),340+ peak_memory_usage: Information::from_bytes(1024),341 exit_status: ExitStatus::default(),342 },343 Measurement {344- time_wall_clock: Second::new(2.03),345- time_user: Second::new(2.03),346- time_system: Second::zero(),347- peak_memory_usage: Byte::new(1024),344+ time_wall_clock: Time::from_seconds(2.03),345+ time_user: Time::from_seconds(2.03),346+ time_system: Time::zero(),347+ peak_memory_usage: Information::from_bytes(1024),348 exit_status: ExitStatus::default(),349 },350 ]),351 parameters: BTreeMap::new(),1 unmodified line353 BenchmarkResult {354 command: String::from("sleep 0.1"),355 measurements: Measurements::new(vec![356 Measurement {357- time_wall_clock: Second::new(0.11),358- time_user: Second::new(0.11),359- time_system: Second::zero(),360- peak_memory_usage: Byte::new(1024),357+ time_wall_clock: Time::from_seconds(0.11),358+ time_user: Time::from_seconds(0.11),359+ time_system: Time::zero(),360+ peak_memory_usage: Information::from_bytes(1024),361 exit_status: ExitStatus::default(),362 },363 Measurement {364- time_wall_clock: Second::new(0.12),365- time_user: Second::new(0.12),366- time_system: Second::zero(),367- peak_memory_usage: Byte::new(1024),364+ time_wall_clock: Time::from_seconds(0.12),365+ time_user: Time::from_seconds(0.12),366+ time_system: Time::zero(),367+ peak_memory_usage: Information::from_bytes(1024),368 exit_status: ExitStatus::default(),369 },370 Measurement {371- time_wall_clock: Second::new(0.13),372- time_user: Second::new(0.13),373- time_system: Second::zero(),374- peak_memory_usage: Byte::new(1024),371+ time_wall_clock: Time::from_seconds(0.13),372+ time_user: Time::from_seconds(0.13),373+ time_system: Time::zero(),374+ peak_memory_usage: Information::from_bytes(1024),375 exit_status: ExitStatus::default(),376 },377 ]),378 parameters: BTreeMap::new(),40 unmodified linesmodified:src/output/warnings.rs+3 added-2 removed
1 use std::fmt;2 3-use crate::benchmark::quantity::Second;3+use crate::benchmark::quantity::{millisecond, Time, TimeQuantity};4 use crate::benchmark::MIN_EXECUTION_TIME;5 use crate::output::format::format_duration;6 7 pub struct OutlierWarningOptions {13 unmodified lines21 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {22 match *self {23 Warnings::FastExecutionTime => write!(24 f,25- "Command took less than {MIN_EXECUTION_TIME} to complete. Note that the results might be \25+ "Command took less than {min_execution_time} to complete. Note that the results might be \26 inaccurate because hyperfine can not calibrate the shell startup time much \27 more precise than this limit. You can try to use the `-N`/`--shell=none` \28 option to disable the shell completely.",29+ min_execution_time = MIN_EXECUTION_TIME.to_string(millisecond)30 ),31 Warnings::NonZeroExitCode => write!(f, "Ignoring non-zero exit code."),32 Warnings::SlowInitialRun(time_first_run, ref options) => write!(33 f,36 unmodified linesmodified:src/timer/unix_timer.rs+5 added-5 removed
6 unmodified lines7 use std::process::{Child, ExitStatus};8 9 use anyhow::Result;10 11-use crate::benchmark::quantity::{Byte, Second};11+use crate::benchmark::quantity::{Information, InformationQuantity, Time, TimeQuantity};12 13 #[derive(Debug, Copy, Clone)]14 struct ResourceUsage {15 /// Total amount of time spent executing in user mode51 unmodified lines67 pub fn start() -> Self {68 Self {}69 }70 71- pub fn stop(&self, child: Child) -> Result<(ExitStatus, Second, Second, Byte)> {71+ pub fn stop(&self, child: Child) -> Result<(ExitStatus, Time, Time, Information)> {72 let (status, usage) = wait4(child)?;73 Ok((74 status,75- Second::new(usage.user_usec),76- Second::new(usage.system_usec),77- Byte::new(u64::try_from(usage.memory_usage_byte).unwrap_or(0)),75+ Time::from_seconds(usage.user_usec),76+ Time::from_seconds(usage.system_usec),77+ Information::from_bytes(u64::try_from(usage.memory_usage_byte).unwrap_or(0)),78 ))79 }80 }modified:src/timer/wall_clock_timer.rs+4 added-3 removed
1 use std::time::Instant;2 3-use crate::benchmark::quantity::Second;3+use crate::benchmark::quantity::{Time, TimeQuantity};4 5 pub struct WallClockTimer {6 start: Instant,7 }6 unmodified lines14 }15 16 pub fn stop(&self) -> Time {17 let duration = self.start.elapsed();18- // TODO19- Second::new(duration.as_secs() as f64 + f64::from(duration.subsec_nanos()) * 1e-9)18+19+ Time::from_seconds(duration.as_secs() as f64)20+ + Time::from_nanoseconds(duration.subsec_nanos() as f64)21 }22 }modified:src/options.rs+3 added-3 removed
5 unmodified lines6 7 use anyhow::{bail, ensure};8 use clap::ArgMatches;9 10-use crate::benchmark::quantity::Second;10+use crate::benchmark::quantity::{Time, TimeQuantity};11 use crate::command::Commands;12 use crate::error::OptionsError;13 use crate::util::units::Unit;14 241 unmodified lines256 fn default() -> Options {257 Options {258 run_bounds: RunBounds::default(),259 warmup_count: 0,260- min_benchmarking_time: Second::new(3.0),260+ min_benchmarking_time: Time::from_seconds(3.0),261 command_failure_action: CmdFailureAction::RaiseError,262 reference_command: None,263 reference_name: None,264 reference_index: None,177 unmodified lines442 _ => None,443 };444 445 if let Some(time) = matches.get_one::<String>("min-benchmarking-time") {446- options.min_benchmarking_time = Second::new(446+ options.min_benchmarking_time = Time::from_seconds(447 time.parse::<f64>()448 .map_err(|e| OptionsError::FloatParsingError("min-benchmarking-time", e))?,449 );450 }127 unmodified linesmodified:Cargo.lock+87 added-9 removed
394 unmodified lines395 "statistical",396 "tempfile",397 "thiserror",398 "uom",399- "windows-sys 0.61.2",399+ "windows-sys 0.59.0",400 ]401 402 [[package]]403 name = "indexmap"101 unmodified lines505 source = "registry+https://github.com/rust-lang/crates.io-index"506 checksum = "61807f77802ff30975e01f4f071c8ba10c022052f98b3294119f3e615d13e5be"507 508 [[package]]509+name = "num"510+version = "0.2.1"511+source = "registry+https://github.com/rust-lang/crates.io-index"512+checksum = "b8536030f9fea7127f841b45bb6243b27255787fb4eb83958aa1ef9d2fdc0c36"513+dependencies = [514+ "num-bigint",515+ "num-complex",516+ "num-integer",517+ "num-iter",518+ "num-rational 0.2.4",519+ "num-traits",520+]521+522+[[package]]523+name = "num-bigint"524+version = "0.2.6"525+source = "registry+https://github.com/rust-lang/crates.io-index"526+checksum = "090c7f9998ee0ff65aa5b723e4009f7b217707f1fb5ea551329cc4d6231fb304"527+dependencies = [528+ "autocfg 1.4.0",529+ "num-integer",530+ "num-traits",531+]532+533+[[package]]534+name = "num-complex"535+version = "0.2.4"536+source = "registry+https://github.com/rust-lang/crates.io-index"537+checksum = "b6b19411a9719e753aff12e5187b74d60d3dc449ec3f4dc21e3989c3f554bc95"538+dependencies = [539+ "autocfg 1.4.0",540+ "num-traits",541+]542+543+[[package]]544+name = "num-integer"545+version = "0.1.46"546+source = "registry+https://github.com/rust-lang/crates.io-index"547+checksum = "7969661fd2958a5cb096e56c8e1ad0444ac2bbcd0061bd28660485a44879858f"548+dependencies = [549+ "num-traits",550+]551+552+[[package]]553+name = "num-iter"554+version = "0.1.45"555+source = "registry+https://github.com/rust-lang/crates.io-index"556+checksum = "1429034a0490724d0075ebb2bc9e875d6503c3cf69e235a8941aa757d83ef5bf"557+dependencies = [558+ "autocfg 1.4.0",559+ "num-integer",560+ "num-traits",561+]562+563+[[package]]564+name = "num-rational"565+version = "0.2.4"566+source = "registry+https://github.com/rust-lang/crates.io-index"567+checksum = "5c000134b5dbf44adc5cb772486d335293351644b801551abe8f75c84cfa4aef"568+dependencies = [569+ "autocfg 1.4.0",570+ "num-bigint",571+ "num-integer",572+ "num-traits",573+]574+575+[[package]]576+name = "num-rational"577+version = "0.4.2"578+source = "registry+https://github.com/rust-lang/crates.io-index"579+checksum = "f83d14da390562dca69fc84082e73e548e1ad308d24accdedd2720017cb37824"580+dependencies = [581+ "num-integer",582+ "num-traits",583+]584+585+[[package]]586 name = "num-traits"587 version = "0.2.19"588 source = "registry+https://github.com/rust-lang/crates.io-index"589 checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841"412 unmodified lines1002 "winnow",1003 ]1004 1005 [[package]]929-name = "toml_parser"930-version = "1.1.3+spec-1.1.0"1006+name = "typenum"1007+version = "1.17.0"1008 source = "registry+https://github.com/rust-lang/crates.io-index"1009+checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825"1010+1011+[[package]]1012+name = "unicode-ident"1013+version = "1.0.13"1014+source = "registry+https://github.com/rust-lang/crates.io-index"1015 checksum = "1d38ac1cf9b95face32296c0a3ede1fdc270627c9d9c02a7274dd6d960dc4d56"1016 dependencies = [1017 "winnow",1018 ]16 unmodified lines1035 source = "registry+https://github.com/rust-lang/crates.io-index"1036 checksum = "7dd6e30e90baa6f72411720665d41d89b9a3d039dc45b8faea1ddd07f617f6af"1037 1038 [[package]]956-name = "unicode-width"957-version = "0.2.2"958-source = "registry+https://github.com/rust-lang/crates.io-index"959-checksum = "b4ac048d71ede7ee76d585517add45da530660ef4390e49b098733c6e897f254"960-961-[[package]]1039 name = "uom"1040 version = "0.36.0"1041 source = "registry+https://github.com/rust-lang/crates.io-index"1042 checksum = "ffd36e5350a65d112584053ee91843955826bf9e56ec0d1351214e01f6d7cd9c"1043 dependencies = [1044+ "num-rational 0.4.2",1045 "num-traits",1046 "typenum",1047 ]1048 213 unmodified linesmodified:Cargo.toml+6 added
26 unmodified lines27 rand = "0.10"28 shell-words = "1.1"29 thiserror = "2.0"30 anyhow = "1.0"31+uom = { version = "0.36.0", default-features = false, features = [32+ "std",33+ "si",34+ "f64",35+ "u64",36+] }37 38 [target.'cfg(not(windows))'.dependencies]39 libc = "0.2"40 48 unmodified lines