From 641451aea69d6f07d346d8ce21f14546ca215de3 Mon Sep 17 00:00:00 2001 From: David Peter Date: Mon, 5 Oct 2026 14:17:14 +0200 Subject: [PATCH] Use uom --- Cargo.lock | 96 +++++++- Cargo.toml | 6 + src/benchmark/benchmark_result.rs | 4 +- src/benchmark/executor.rs | 32 +-- src/benchmark/measurement.rs | 37 +-- src/benchmark/mod.rs | 12 +- src/benchmark/quantity.rs | 364 ++++++++++++------------------ src/benchmark/relative_speed.rs | 27 ++- src/benchmark/scheduler.rs | 48 ++-- src/export/csv.rs | 54 ++--- src/export/tests.rs | 194 ++++++++-------- src/options.rs | 6 +- src/output/warnings.rs | 5 +- src/timer/unix_timer.rs | 10 +- src/timer/wall_clock_timer.rs | 7 +- 15 files changed, 459 insertions(+), 443 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 12e9701..e223749 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -396,7 +396,7 @@ dependencies = [ "tempfile", "thiserror", "uom", - "windows-sys 0.61.2", + "windows-sys 0.59.0", ] [[package]] @@ -505,6 +505,83 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "61807f77802ff30975e01f4f071c8ba10c022052f98b3294119f3e615d13e5be" +[[package]] +name = "num" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8536030f9fea7127f841b45bb6243b27255787fb4eb83958aa1ef9d2fdc0c36" +dependencies = [ + "num-bigint", + "num-complex", + "num-integer", + "num-iter", + "num-rational 0.2.4", + "num-traits", +] + +[[package]] +name = "num-bigint" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "090c7f9998ee0ff65aa5b723e4009f7b217707f1fb5ea551329cc4d6231fb304" +dependencies = [ + "autocfg 1.4.0", + "num-integer", + "num-traits", +] + +[[package]] +name = "num-complex" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6b19411a9719e753aff12e5187b74d60d3dc449ec3f4dc21e3989c3f554bc95" +dependencies = [ + "autocfg 1.4.0", + "num-traits", +] + +[[package]] +name = "num-integer" +version = "0.1.46" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7969661fd2958a5cb096e56c8e1ad0444ac2bbcd0061bd28660485a44879858f" +dependencies = [ + "num-traits", +] + +[[package]] +name = "num-iter" +version = "0.1.45" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1429034a0490724d0075ebb2bc9e875d6503c3cf69e235a8941aa757d83ef5bf" +dependencies = [ + "autocfg 1.4.0", + "num-integer", + "num-traits", +] + +[[package]] +name = "num-rational" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c000134b5dbf44adc5cb772486d335293351644b801551abe8f75c84cfa4aef" +dependencies = [ + "autocfg 1.4.0", + "num-bigint", + "num-integer", + "num-traits", +] + +[[package]] +name = "num-rational" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f83d14da390562dca69fc84082e73e548e1ad308d24accdedd2720017cb37824" +dependencies = [ + "num-integer", + "num-traits", +] + [[package]] name = "num-traits" version = "0.2.19" @@ -926,8 +1003,14 @@ dependencies = [ ] [[package]] -name = "toml_parser" -version = "1.1.3+spec-1.1.0" +name = "typenum" +version = "1.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" + +[[package]] +name = "unicode-ident" +version = "1.0.13" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1d38ac1cf9b95face32296c0a3ede1fdc270627c9d9c02a7274dd6d960dc4d56" dependencies = [ @@ -952,18 +1035,13 @@ version = "0.1.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7dd6e30e90baa6f72411720665d41d89b9a3d039dc45b8faea1ddd07f617f6af" -[[package]] -name = "unicode-width" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b4ac048d71ede7ee76d585517add45da530660ef4390e49b098733c6e897f254" - [[package]] name = "uom" version = "0.36.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ffd36e5350a65d112584053ee91843955826bf9e56ec0d1351214e01f6d7cd9c" dependencies = [ + "num-rational 0.4.2", "num-traits", "typenum", ] diff --git a/Cargo.toml b/Cargo.toml index 5e5701e..1c1891c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -28,6 +28,12 @@ rand = "0.10" shell-words = "1.1" thiserror = "2.0" anyhow = "1.0" +uom = { version = "0.36.0", default-features = false, features = [ + "std", + "si", + "f64", + "u64", +] } [target.'cfg(not(windows))'.dependencies] libc = "0.2" diff --git a/src/benchmark/benchmark_result.rs b/src/benchmark/benchmark_result.rs index 826bcee..f990c94 100644 --- a/src/benchmark/benchmark_result.rs +++ b/src/benchmark/benchmark_result.rs @@ -2,7 +2,7 @@ use std::collections::BTreeMap; use serde::Serialize; -use crate::benchmark::{measurement::Measurements, quantity::Second}; +use crate::benchmark::{measurement::Measurements, quantity::Time}; /// Parameter value and whether it was used in the command line template #[derive(Debug, Default, Clone, Serialize, PartialEq)] @@ -37,7 +37,7 @@ pub struct BenchmarkResult { impl BenchmarkResult { /// The average wall clock time - pub fn mean_wall_clock_time(&self) -> Second { + pub fn mean_wall_clock_time(&self) -> Time { self.measurements.time_wall_clock_mean() } diff --git a/src/benchmark/executor.rs b/src/benchmark/executor.rs index f3816e5..a6e8150 100644 --- a/src/benchmark/executor.rs +++ b/src/benchmark/executor.rs @@ -4,8 +4,9 @@ use std::process::ExitStatus; use crate::benchmark::measurement::Measurement; use crate::benchmark::measurement::Measurements; -use crate::benchmark::quantity::Byte; -use crate::benchmark::quantity::Second; +use crate::benchmark::quantity::Information; +use crate::benchmark::quantity::InformationQuantity; +use crate::benchmark::quantity::{Time, TimeQuantity}; use crate::command::Command; use crate::options::{ CmdFailureAction, CommandInputPolicy, CommandOutputPolicy, Options, OutputStyleOption, Shell, @@ -172,8 +173,8 @@ impl Executor for RawExecutor<'_> { Ok(()) } - fn time_overhead(&self) -> Second { - Second::zero() + fn time_overhead(&self) -> Time { + Time::zero() } } @@ -223,9 +224,9 @@ impl Executor for ShellExecutor<'_> { )?; // Subtract shell spawning time - fn ensure_non_negative(time: Second) -> Second { - if time < Second::zero() { - Second::zero() + fn ensure_non_negative(time: Time) -> Time { + if time < Time::zero() { + Time::zero() } else { time } @@ -310,7 +311,7 @@ impl Executor for ShellExecutor<'_> { Ok(()) } - fn time_overhead(&self) -> Second { + fn time_overhead(&self) -> Time { self.shell_spawning_time.as_ref().unwrap().time_wall_clock } } @@ -327,7 +328,7 @@ impl MockExecutor { fn extract_time>(sleep_command: S) -> Time { assert!(sleep_command.as_ref().starts_with("sleep ")); - Second::new( + Time::from_seconds( sleep_command .as_ref() .trim_start_matches("sleep ") @@ -359,9 +360,9 @@ impl Executor for MockExecutor { Ok(Measurement { time_wall_clock: Self::extract_time(command.get_command_line()), - time_user: Second::zero(), - time_system: Second::zero(), - peak_memory_usage: Byte::new(0), + time_user: Time::zero(), + time_system: Time::zero(), + peak_memory_usage: Information::from_bytes(0), exit_status, }) } @@ -372,7 +373,7 @@ impl Executor for MockExecutor { fn time_overhead(&self) -> Time { match &self.shell { - None => Second::zero(), + None => Time::zero(), Some(shell) => Self::extract_time(shell), } } @@ -380,5 +381,8 @@ impl Executor for MockExecutor { #[test] fn test_mock_executor_extract_time() { - assert_eq!(MockExecutor::extract_time("sleep 0.1"), Second::new(0.1)); + assert_eq!( + MockExecutor::extract_time("sleep 0.1"), + Time::from_seconds(0.1) + ); } diff --git a/src/benchmark/measurement.rs b/src/benchmark/measurement.rs index 3708587..7895b73 100644 --- a/src/benchmark/measurement.rs +++ b/src/benchmark/measurement.rs @@ -2,7 +2,10 @@ use std::process::ExitStatus; use serde::Serialize; -use crate::benchmark::quantity::{max, mean, median, min, standard_deviation, Byte, Second}; +use crate::benchmark::quantity::{ + max, mean, median, min, second, serialize_information, serialize_time, standard_deviation, + Information, Time, TimeQuantity, +}; use crate::outlier_detection::modified_zscores; use crate::util::exit_code::extract_exit_code; @@ -20,16 +23,20 @@ where #[derive(Debug, Clone, Default, Serialize, PartialEq)] pub struct Measurement { /// Elapsed wall clock time (real time) - pub time_wall_clock: Second, + #[serde(serialize_with = "serialize_time")] + pub time_wall_clock: Time, /// Time spent in user mode - pub time_user: Second, + #[serde(serialize_with = "serialize_time")] + pub time_user: Time, /// Time spent in kernel mode - pub time_system: Second, + #[serde(serialize_with = "serialize_time")] + pub time_system: Time, /// Maximum memory usage of the process - pub peak_memory_usage: Byte, + #[serde(serialize_with = "serialize_information")] + pub peak_memory_usage: Information, // The exit status of the process #[serde(rename = "exit_code", serialize_with = "serialize_exit_status")] @@ -58,7 +65,7 @@ impl Measurements { self.measurements.push(measurement); } - pub fn wall_clock_times(&self) -> Vec { + pub fn wall_clock_times(&self) -> Vec