From 3494c8abe6b5178ef020e6761db2173e1cc1ee89 Mon Sep 17 00:00:00 2001 From: David Peter Date: Mon, 5 Oct 2026 14:18:58 +0200 Subject: [PATCH] Remove alternative constructors --- src/benchmark/executor.rs | 10 +-- src/benchmark/relative_speed.rs | 5 +- src/export/csv.rs | 38 ++++----- src/export/tests.rs | 146 ++++++++++++++++---------------- src/options.rs | 6 +- src/timer/unix_timer.rs | 8 +- src/timer/wall_clock_timer.rs | 6 +- src/timer/windows_timer.rs | 6 +- 8 files changed, 112 insertions(+), 113 deletions(-) diff --git a/src/benchmark/executor.rs b/src/benchmark/executor.rs index 571f248..ddc0231 100644 --- a/src/benchmark/executor.rs +++ b/src/benchmark/executor.rs @@ -9,9 +9,7 @@ use crate::options::{ CmdFailureAction, CommandInputPolicy, CommandOutputPolicy, Options, OutputStyleOption, Shell, }; use crate::output::progress_bar::get_progress_bar; -use crate::quantity::Information; -use crate::quantity::InformationQuantity; -use crate::quantity::{Time, TimeQuantity}; +use crate::quantity::{byte, second, Information, Time, TimeQuantity}; use crate::timer::execute_and_measure; use crate::util::randomized_environment_offset; @@ -316,7 +314,7 @@ impl MockExecutor { fn extract_time>(sleep_command: S) -> Time { assert!(sleep_command.as_ref().starts_with("sleep ")); - Time::from_seconds( + Time::new::( sleep_command .as_ref() .trim_start_matches("sleep ") @@ -350,7 +348,7 @@ impl Executor for MockExecutor { time_wall_clock: Self::extract_time(command.get_command_line()), time_user: Time::zero(), time_system: Time::zero(), - peak_memory_usage: Information::from_bytes(0), + peak_memory_usage: Information::new::(0), exit_status, }) } @@ -371,6 +369,6 @@ impl Executor for MockExecutor { fn test_mock_executor_extract_time() { assert_eq!( MockExecutor::extract_time("sleep 0.1"), - Time::from_seconds(0.1) + Time::new::(0.1) ); } diff --git a/src/benchmark/relative_speed.rs b/src/benchmark/relative_speed.rs index ba6650b..d722723 100644 --- a/src/benchmark/relative_speed.rs +++ b/src/benchmark/relative_speed.rs @@ -154,13 +154,14 @@ fn create_result(name: &str, mean: f64) -> BenchmarkResult { use std::collections::BTreeMap; use crate::benchmark::measurement::{Measurement, Measurements}; + use crate::quantity::second; BenchmarkResult { command: name.into(), measurements: Measurements { measurements: vec![Measurement { - time_wall_clock: Time::from_seconds(mean), - time_user: Time::from_seconds(mean), + time_wall_clock: Time::new::(mean), + time_user: Time::new::(mean), ..Default::default() }], }, diff --git a/src/export/csv.rs b/src/export/csv.rs index d5978db..02d44b7 100644 --- a/src/export/csv.rs +++ b/src/export/csv.rs @@ -69,7 +69,7 @@ impl Exporter for CsvExporter { fn test_csv() { use crate::benchmark::benchmark_result::Parameter; use crate::benchmark::measurement::{Measurement, Measurements}; - use crate::quantity::{Information, InformationQuantity, Time, TimeQuantity}; + use crate::quantity::{byte, Information, Time, TimeQuantity}; use std::collections::BTreeMap; use std::process::ExitStatus; @@ -81,24 +81,24 @@ fn test_csv() { command: String::from("command_a"), measurements: Measurements::new(vec![ Measurement { - time_wall_clock: Time::from_seconds(7.0), - time_user: Time::from_seconds(7.0), + time_wall_clock: Time::new::(7.0), + time_user: Time::new::(7.0), time_system: Time::zero(), - peak_memory_usage: Information::from_bytes(1024), + peak_memory_usage: Information::new::(1024), exit_status: ExitStatus::default(), }, Measurement { - time_wall_clock: Time::from_seconds(8.0), - time_user: Time::from_seconds(8.0), + time_wall_clock: Time::new::(8.0), + time_user: Time::new::(8.0), time_system: Time::zero(), - peak_memory_usage: Information::from_bytes(1024), + peak_memory_usage: Information::new::(1024), exit_status: ExitStatus::default(), }, Measurement { - time_wall_clock: Time::from_seconds(12.0), - time_user: Time::from_seconds(12.0), + time_wall_clock: Time::new::(12.0), + time_user: Time::new::(12.0), time_system: Time::zero(), - peak_memory_usage: Information::from_bytes(1024), + peak_memory_usage: Information::new::(1024), exit_status: ExitStatus::default(), }, ]), @@ -125,24 +125,24 @@ fn test_csv() { command: String::from("command_b"), measurements: Measurements::new(vec![ Measurement { - time_wall_clock: Time::from_seconds(17.0), - time_user: Time::from_seconds(17.0), + time_wall_clock: Time::new::(17.0), + time_user: Time::new::(17.0), time_system: Time::zero(), - peak_memory_usage: Information::from_bytes(1024), + peak_memory_usage: Information::new::(1024), exit_status: ExitStatus::default(), }, Measurement { - time_wall_clock: Time::from_seconds(18.0), - time_user: Time::from_seconds(18.0), + time_wall_clock: Time::new::(18.0), + time_user: Time::new::(18.0), time_system: Time::zero(), - peak_memory_usage: Information::from_bytes(1024), + peak_memory_usage: Information::new::(1024), exit_status: ExitStatus::default(), }, Measurement { - time_wall_clock: Time::from_seconds(19.0), - time_user: Time::from_seconds(19.0), + time_wall_clock: Time::new::(19.0), + time_user: Time::new::(19.0), time_system: Time::zero(), - peak_memory_usage: Information::from_bytes(1024), + peak_memory_usage: Information::new::(1024), exit_status: ExitStatus::default(), }, ]), diff --git a/src/export/tests.rs b/src/export/tests.rs index e8fa096..e67cf74 100644 --- a/src/export/tests.rs +++ b/src/export/tests.rs @@ -3,7 +3,7 @@ use crate::benchmark::benchmark_result::BenchmarkResult; 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::quantity::{byte, second, Information, Time, TimeQuantity}; use crate::util::units::TimeUnit; use crate::{export::markdown::MarkdownExporter, options::SortOrder}; use std::collections::BTreeMap; @@ -31,24 +31,24 @@ fn test_markup_export_auto_ms() { command: String::from("sleep 0.1"), measurements: Measurements::new(vec![ Measurement { - time_wall_clock: Time::from_seconds(0.09), - time_user: Time::from_seconds(0.09), + time_wall_clock: Time::new::(0.09), + time_user: Time::new::(0.09), time_system: Time::zero(), - peak_memory_usage: Information::from_bytes(1024), + peak_memory_usage: Information::new::(1024), exit_status: ExitStatus::default(), }, Measurement { - time_wall_clock: Time::from_seconds(0.10), - time_user: Time::from_seconds(0.10), + time_wall_clock: Time::new::(0.10), + time_user: Time::new::(0.10), time_system: Time::zero(), - peak_memory_usage: Information::from_bytes(1024), + peak_memory_usage: Information::new::(1024), exit_status: ExitStatus::default(), }, Measurement { - time_wall_clock: Time::from_seconds(0.14), - time_user: Time::from_seconds(0.14), + time_wall_clock: Time::new::(0.14), + time_user: Time::new::(0.14), time_system: Time::zero(), - peak_memory_usage: Information::from_bytes(1024), + peak_memory_usage: Information::new::(1024), exit_status: ExitStatus::default(), }, ]), @@ -58,24 +58,24 @@ fn test_markup_export_auto_ms() { command: String::from("sleep 2"), measurements: Measurements::new(vec![ Measurement { - time_wall_clock: Time::from_seconds(2.0), - time_user: Time::from_seconds(2.0), + time_wall_clock: Time::new::(2.0), + time_user: Time::new::(2.0), time_system: Time::zero(), - peak_memory_usage: Information::from_bytes(1024), + peak_memory_usage: Information::new::(1024), exit_status: ExitStatus::default(), }, Measurement { - time_wall_clock: Time::from_seconds(3.0), - time_user: Time::from_seconds(3.0), + time_wall_clock: Time::new::(3.0), + time_user: Time::new::(3.0), time_system: Time::zero(), - peak_memory_usage: Information::from_bytes(1024), + peak_memory_usage: Information::new::(1024), exit_status: ExitStatus::default(), }, Measurement { - time_wall_clock: Time::from_seconds(4.0), - time_user: Time::from_seconds(4.0), + time_wall_clock: Time::new::(4.0), + time_user: Time::new::(4.0), time_system: Time::zero(), - peak_memory_usage: Information::from_bytes(1024), + peak_memory_usage: Information::new::(1024), exit_status: ExitStatus::default(), }, ]), @@ -130,24 +130,24 @@ fn test_markup_export_auto_s() { command: String::from("sleep 2"), measurements: Measurements::new(vec![ Measurement { - time_wall_clock: Time::from_seconds(2.1), - time_user: Time::from_seconds(2.1), + time_wall_clock: Time::new::(2.1), + time_user: Time::new::(2.1), time_system: Time::zero(), - peak_memory_usage: Information::from_bytes(1024), + peak_memory_usage: Information::new::(1024), exit_status: ExitStatus::default(), }, Measurement { - time_wall_clock: Time::from_seconds(2.2), - time_user: Time::from_seconds(2.2), + time_wall_clock: Time::new::(2.2), + time_user: Time::new::(2.2), time_system: Time::zero(), - peak_memory_usage: Information::from_bytes(1024), + peak_memory_usage: Information::new::(1024), exit_status: ExitStatus::default(), }, Measurement { - time_wall_clock: Time::from_seconds(2.3), - time_user: Time::from_seconds(2.3), + time_wall_clock: Time::new::(2.3), + time_user: Time::new::(2.3), time_system: Time::zero(), - peak_memory_usage: Information::from_bytes(1024), + peak_memory_usage: Information::new::(1024), exit_status: ExitStatus::default(), }, ]), @@ -157,24 +157,24 @@ fn test_markup_export_auto_s() { command: String::from("sleep 0.1"), measurements: Measurements::new(vec![ Measurement { - time_wall_clock: Time::from_seconds(0.1), - time_user: Time::from_seconds(0.1), + time_wall_clock: Time::new::(0.1), + time_user: Time::new::(0.1), time_system: Time::zero(), - peak_memory_usage: Information::from_bytes(1024), + peak_memory_usage: Information::new::(1024), exit_status: ExitStatus::default(), }, Measurement { - time_wall_clock: Time::from_seconds(0.2), - time_user: Time::from_seconds(0.2), + time_wall_clock: Time::new::(0.2), + time_user: Time::new::(0.2), time_system: Time::zero(), - peak_memory_usage: Information::from_bytes(1024), + peak_memory_usage: Information::new::(1024), exit_status: ExitStatus::default(), }, Measurement { - time_wall_clock: Time::from_seconds(0.3), - time_user: Time::from_seconds(0.3), + time_wall_clock: Time::new::(0.3), + time_user: Time::new::(0.3), time_system: Time::zero(), - peak_memory_usage: Information::from_bytes(1024), + peak_memory_usage: Information::new::(1024), exit_status: ExitStatus::default(), }, ]), @@ -229,24 +229,24 @@ fn test_markup_export_manual_ms() { command: String::from("sleep 2"), measurements: Measurements::new(vec![ Measurement { - time_wall_clock: Time::from_seconds(2.1), - time_user: Time::from_seconds(2.1), + time_wall_clock: Time::new::(2.1), + time_user: Time::new::(2.1), time_system: Time::zero(), - peak_memory_usage: Information::from_bytes(1024), + peak_memory_usage: Information::new::(1024), exit_status: ExitStatus::default(), }, Measurement { - time_wall_clock: Time::from_seconds(2.2), - time_user: Time::from_seconds(2.2), + time_wall_clock: Time::new::(2.2), + time_user: Time::new::(2.2), time_system: Time::zero(), - peak_memory_usage: Information::from_bytes(1024), + peak_memory_usage: Information::new::(1024), exit_status: ExitStatus::default(), }, Measurement { - time_wall_clock: Time::from_seconds(2.3), - time_user: Time::from_seconds(2.3), + time_wall_clock: Time::new::(2.3), + time_user: Time::new::(2.3), time_system: Time::zero(), - peak_memory_usage: Information::from_bytes(1024), + peak_memory_usage: Information::new::(1024), exit_status: ExitStatus::default(), }, ]), @@ -256,24 +256,24 @@ fn test_markup_export_manual_ms() { command: String::from("sleep 0.1"), measurements: Measurements::new(vec![ Measurement { - time_wall_clock: Time::from_seconds(0.1), - time_user: Time::from_seconds(0.1), + time_wall_clock: Time::new::(0.1), + time_user: Time::new::(0.1), time_system: Time::zero(), - peak_memory_usage: Information::from_bytes(1024), + peak_memory_usage: Information::new::(1024), exit_status: ExitStatus::default(), }, Measurement { - time_wall_clock: Time::from_seconds(0.2), - time_user: Time::from_seconds(0.2), + time_wall_clock: Time::new::(0.2), + time_user: Time::new::(0.2), time_system: Time::zero(), - peak_memory_usage: Information::from_bytes(1024), + peak_memory_usage: Information::new::(1024), exit_status: ExitStatus::default(), }, Measurement { - time_wall_clock: Time::from_seconds(0.3), - time_user: Time::from_seconds(0.3), + time_wall_clock: Time::new::(0.3), + time_user: Time::new::(0.3), time_system: Time::zero(), - peak_memory_usage: Information::from_bytes(1024), + peak_memory_usage: Information::new::(1024), exit_status: ExitStatus::default(), }, ]), @@ -327,24 +327,24 @@ fn test_markup_export_manual_s() { command: String::from("sleep 2"), measurements: Measurements::new(vec![ Measurement { - time_wall_clock: Time::from_seconds(2.01), - time_user: Time::from_seconds(2.01), + time_wall_clock: Time::new::(2.01), + time_user: Time::new::(2.01), time_system: Time::zero(), - peak_memory_usage: Information::from_bytes(1024), + peak_memory_usage: Information::new::(1024), exit_status: ExitStatus::default(), }, Measurement { - time_wall_clock: Time::from_seconds(2.02), - time_user: Time::from_seconds(2.02), + time_wall_clock: Time::new::(2.02), + time_user: Time::new::(2.02), time_system: Time::zero(), - peak_memory_usage: Information::from_bytes(1024), + peak_memory_usage: Information::new::(1024), exit_status: ExitStatus::default(), }, Measurement { - time_wall_clock: Time::from_seconds(2.03), - time_user: Time::from_seconds(2.03), + time_wall_clock: Time::new::(2.03), + time_user: Time::new::(2.03), time_system: Time::zero(), - peak_memory_usage: Information::from_bytes(1024), + peak_memory_usage: Information::new::(1024), exit_status: ExitStatus::default(), }, ]), @@ -354,24 +354,24 @@ fn test_markup_export_manual_s() { command: String::from("sleep 0.1"), measurements: Measurements::new(vec![ Measurement { - time_wall_clock: Time::from_seconds(0.11), - time_user: Time::from_seconds(0.11), + time_wall_clock: Time::new::(0.11), + time_user: Time::new::(0.11), time_system: Time::zero(), - peak_memory_usage: Information::from_bytes(1024), + peak_memory_usage: Information::new::(1024), exit_status: ExitStatus::default(), }, Measurement { - time_wall_clock: Time::from_seconds(0.12), - time_user: Time::from_seconds(0.12), + time_wall_clock: Time::new::(0.12), + time_user: Time::new::(0.12), time_system: Time::zero(), - peak_memory_usage: Information::from_bytes(1024), + peak_memory_usage: Information::new::(1024), exit_status: ExitStatus::default(), }, Measurement { - time_wall_clock: Time::from_seconds(0.13), - time_user: Time::from_seconds(0.13), + time_wall_clock: Time::new::(0.13), + time_user: Time::new::(0.13), time_system: Time::zero(), - peak_memory_usage: Information::from_bytes(1024), + peak_memory_usage: Information::new::(1024), exit_status: ExitStatus::default(), }, ]), diff --git a/src/options.rs b/src/options.rs index 35eceb6..290d870 100644 --- a/src/options.rs +++ b/src/options.rs @@ -9,7 +9,7 @@ use clap::ArgMatches; use crate::command::Commands; use crate::error::OptionsError; -use crate::quantity::{Time, TimeQuantity}; +use crate::quantity::{second, Time}; use crate::util::units::TimeUnit; use anyhow::Result; @@ -257,7 +257,7 @@ impl Default for Options { Options { run_bounds: RunBounds::default(), warmup_count: 0, - min_benchmarking_time: Time::from_seconds(3.0), + min_benchmarking_time: Time::new::(3.0), command_failure_action: CmdFailureAction::RaiseError, reference_command: None, reference_name: None, @@ -443,7 +443,7 @@ impl Options { }; if let Some(time) = matches.get_one::("min-benchmarking-time") { - options.min_benchmarking_time = Time::from_seconds( + options.min_benchmarking_time = Time::new::( time.parse::() .map_err(|e| OptionsError::FloatParsingError("min-benchmarking-time", e))?, ); diff --git a/src/timer/unix_timer.rs b/src/timer/unix_timer.rs index 698e0b2..1ff169d 100644 --- a/src/timer/unix_timer.rs +++ b/src/timer/unix_timer.rs @@ -8,7 +8,7 @@ use std::process::{Child, ExitStatus}; use anyhow::Result; -use crate::quantity::{Information, InformationQuantity, Time, TimeQuantity}; +use crate::quantity::{byte, kibibyte, microsecond, second, Information, Time}; #[derive(Debug, Copy, Clone)] struct ResourceUsage { @@ -27,7 +27,7 @@ fn convert_timeval(tv: libc::timeval) -> Time { let sec = tv.tv_sec as f64; let usec = tv.tv_usec as f64; - Time::from_seconds(sec) + Time::from_microseconds(usec) + Time::new::(sec) + Time::new::(usec) } #[allow(clippy::useless_conversion)] @@ -47,9 +47,9 @@ fn wait4(mut child: Child) -> io::Result<(ExitStatus, ResourceUsage)> { let memory_usage_byte = if cfg!(target_os = "macos") || cfg!(target_os = "ios") { // Linux and *BSD return the value in KibiBytes, Darwin flavors in bytes - Information::from_bytes(u64::try_from(rusage.ru_maxrss).unwrap_or(0)) + Information::new::(u64::try_from(rusage.ru_maxrss).unwrap_or(0)) } else { - Information::from_kibibytes(u64::try_from(rusage.ru_maxrss).unwrap_or(0)) + Information::new::(u64::try_from(rusage.ru_maxrss).unwrap_or(0)) }; Ok(( diff --git a/src/timer/wall_clock_timer.rs b/src/timer/wall_clock_timer.rs index 68a543a..3a7233a 100644 --- a/src/timer/wall_clock_timer.rs +++ b/src/timer/wall_clock_timer.rs @@ -1,6 +1,6 @@ use std::time::Instant; -use crate::quantity::{Time, TimeQuantity}; +use crate::quantity::{nanosecond, second, Time}; pub struct WallClockTimer { start: Instant, @@ -16,7 +16,7 @@ impl WallClockTimer { pub fn stop(&self) -> Time { let duration = self.start.elapsed(); - Time::from_seconds(duration.as_secs() as f64) - + Time::from_nanoseconds(duration.subsec_nanos() as f64) + Time::new::(duration.as_secs() as f64) + + Time::new::(duration.subsec_nanos() as f64) } } diff --git a/src/timer/windows_timer.rs b/src/timer/windows_timer.rs index e62bb43..07423e5 100644 --- a/src/timer/windows_timer.rs +++ b/src/timer/windows_timer.rs @@ -30,7 +30,7 @@ use windows_sys::{ }, }; -use crate::quantity::{Information, InformationQuantity, Time, TimeQuantity}; +use crate::quantity::{nanosecond, Information, InformationQuantity, Time}; #[cfg(not(feature = "windows_process_extensions_main_thread_handle"))] #[allow(non_upper_case_globals)] @@ -108,13 +108,13 @@ impl CPUTimer { // The `TotalUserTime` is "The total amount of user-mode execution time for // all active processes associated with the job, as well as all terminated processes no // longer associated with the job, in 100-nanosecond ticks." - let user_time = Time::from_nanoseconds((job_object_info.TotalUserTime as f64) * 100.0); + let user_time = Time::new::((job_object_info.TotalUserTime as f64) * 100.0); // The `TotalKernelTime` is "The total amount of kernel-mode execution time // for all active processes associated with the job, as well as all terminated // processes no longer associated with the job, in 100-nanosecond ticks." let system_time = - Time::from_nanoseconds((job_object_info.TotalKernelTime as f64) * 100.0); + Time::new::((job_object_info.TotalKernelTime as f64) * 100.0); Ok((user_time, system_time, Information::zero(), status)) } else {