Remove alternative constructors

This commit is contained in:
David Peter authored and David Peter committed 2026-10-05 15:59:43 +02:00
1 parent f57c4e6d78
commit 3494c8abe6
8 files changed
+112 -113

No files matched your search

+4 -6
View File
@@ -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<S: AsRef<str>>(sleep_command: S) -> Time {
assert!(sleep_command.as_ref().starts_with("sleep "));
Time::from_seconds(
Time::new::<second>(
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::<byte>(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::<second>(0.1)
);
}
+3 -2
View File
@@ -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::<second>(mean),
time_user: Time::new::<second>(mean),
..Default::default()
}],
},
+19 -19
View File
@@ -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::<second>(7.0),
time_user: Time::new::<second>(7.0),
time_system: Time::zero(),
peak_memory_usage: Information::from_bytes(1024),
peak_memory_usage: Information::new::<byte>(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::<second>(8.0),
time_user: Time::new::<second>(8.0),
time_system: Time::zero(),
peak_memory_usage: Information::from_bytes(1024),
peak_memory_usage: Information::new::<byte>(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::<second>(12.0),
time_user: Time::new::<second>(12.0),
time_system: Time::zero(),
peak_memory_usage: Information::from_bytes(1024),
peak_memory_usage: Information::new::<byte>(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::<second>(17.0),
time_user: Time::new::<second>(17.0),
time_system: Time::zero(),
peak_memory_usage: Information::from_bytes(1024),
peak_memory_usage: Information::new::<byte>(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::<second>(18.0),
time_user: Time::new::<second>(18.0),
time_system: Time::zero(),
peak_memory_usage: Information::from_bytes(1024),
peak_memory_usage: Information::new::<byte>(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::<second>(19.0),
time_user: Time::new::<second>(19.0),
time_system: Time::zero(),
peak_memory_usage: Information::from_bytes(1024),
peak_memory_usage: Information::new::<byte>(1024),
exit_status: ExitStatus::default(),
},
]),
+73 -73
View File
@@ -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::<second>(0.09),
time_user: Time::new::<second>(0.09),
time_system: Time::zero(),
peak_memory_usage: Information::from_bytes(1024),
peak_memory_usage: Information::new::<byte>(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::<second>(0.10),
time_user: Time::new::<second>(0.10),
time_system: Time::zero(),
peak_memory_usage: Information::from_bytes(1024),
peak_memory_usage: Information::new::<byte>(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::<second>(0.14),
time_user: Time::new::<second>(0.14),
time_system: Time::zero(),
peak_memory_usage: Information::from_bytes(1024),
peak_memory_usage: Information::new::<byte>(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::<second>(2.0),
time_user: Time::new::<second>(2.0),
time_system: Time::zero(),
peak_memory_usage: Information::from_bytes(1024),
peak_memory_usage: Information::new::<byte>(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::<second>(3.0),
time_user: Time::new::<second>(3.0),
time_system: Time::zero(),
peak_memory_usage: Information::from_bytes(1024),
peak_memory_usage: Information::new::<byte>(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::<second>(4.0),
time_user: Time::new::<second>(4.0),
time_system: Time::zero(),
peak_memory_usage: Information::from_bytes(1024),
peak_memory_usage: Information::new::<byte>(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::<second>(2.1),
time_user: Time::new::<second>(2.1),
time_system: Time::zero(),
peak_memory_usage: Information::from_bytes(1024),
peak_memory_usage: Information::new::<byte>(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::<second>(2.2),
time_user: Time::new::<second>(2.2),
time_system: Time::zero(),
peak_memory_usage: Information::from_bytes(1024),
peak_memory_usage: Information::new::<byte>(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::<second>(2.3),
time_user: Time::new::<second>(2.3),
time_system: Time::zero(),
peak_memory_usage: Information::from_bytes(1024),
peak_memory_usage: Information::new::<byte>(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::<second>(0.1),
time_user: Time::new::<second>(0.1),
time_system: Time::zero(),
peak_memory_usage: Information::from_bytes(1024),
peak_memory_usage: Information::new::<byte>(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::<second>(0.2),
time_user: Time::new::<second>(0.2),
time_system: Time::zero(),
peak_memory_usage: Information::from_bytes(1024),
peak_memory_usage: Information::new::<byte>(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::<second>(0.3),
time_user: Time::new::<second>(0.3),
time_system: Time::zero(),
peak_memory_usage: Information::from_bytes(1024),
peak_memory_usage: Information::new::<byte>(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::<second>(2.1),
time_user: Time::new::<second>(2.1),
time_system: Time::zero(),
peak_memory_usage: Information::from_bytes(1024),
peak_memory_usage: Information::new::<byte>(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::<second>(2.2),
time_user: Time::new::<second>(2.2),
time_system: Time::zero(),
peak_memory_usage: Information::from_bytes(1024),
peak_memory_usage: Information::new::<byte>(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::<second>(2.3),
time_user: Time::new::<second>(2.3),
time_system: Time::zero(),
peak_memory_usage: Information::from_bytes(1024),
peak_memory_usage: Information::new::<byte>(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::<second>(0.1),
time_user: Time::new::<second>(0.1),
time_system: Time::zero(),
peak_memory_usage: Information::from_bytes(1024),
peak_memory_usage: Information::new::<byte>(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::<second>(0.2),
time_user: Time::new::<second>(0.2),
time_system: Time::zero(),
peak_memory_usage: Information::from_bytes(1024),
peak_memory_usage: Information::new::<byte>(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::<second>(0.3),
time_user: Time::new::<second>(0.3),
time_system: Time::zero(),
peak_memory_usage: Information::from_bytes(1024),
peak_memory_usage: Information::new::<byte>(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::<second>(2.01),
time_user: Time::new::<second>(2.01),
time_system: Time::zero(),
peak_memory_usage: Information::from_bytes(1024),
peak_memory_usage: Information::new::<byte>(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::<second>(2.02),
time_user: Time::new::<second>(2.02),
time_system: Time::zero(),
peak_memory_usage: Information::from_bytes(1024),
peak_memory_usage: Information::new::<byte>(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::<second>(2.03),
time_user: Time::new::<second>(2.03),
time_system: Time::zero(),
peak_memory_usage: Information::from_bytes(1024),
peak_memory_usage: Information::new::<byte>(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::<second>(0.11),
time_user: Time::new::<second>(0.11),
time_system: Time::zero(),
peak_memory_usage: Information::from_bytes(1024),
peak_memory_usage: Information::new::<byte>(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::<second>(0.12),
time_user: Time::new::<second>(0.12),
time_system: Time::zero(),
peak_memory_usage: Information::from_bytes(1024),
peak_memory_usage: Information::new::<byte>(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::<second>(0.13),
time_user: Time::new::<second>(0.13),
time_system: Time::zero(),
peak_memory_usage: Information::from_bytes(1024),
peak_memory_usage: Information::new::<byte>(1024),
exit_status: ExitStatus::default(),
},
]),
+3 -3
View File
@@ -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::<second>(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::<String>("min-benchmarking-time") {
options.min_benchmarking_time = Time::from_seconds(
options.min_benchmarking_time = Time::new::<second>(
time.parse::<f64>()
.map_err(|e| OptionsError::FloatParsingError("min-benchmarking-time", e))?,
);
+4 -4
View File
@@ -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::<second>(sec) + Time::new::<microsecond>(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::<byte>(u64::try_from(rusage.ru_maxrss).unwrap_or(0))
} else {
Information::from_kibibytes(u64::try_from(rusage.ru_maxrss).unwrap_or(0))
Information::new::<kibibyte>(u64::try_from(rusage.ru_maxrss).unwrap_or(0))
};
Ok((
+3 -3
View File
@@ -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::<second>(duration.as_secs() as f64)
+ Time::new::<nanosecond>(duration.subsec_nanos() as f64)
}
}
+3 -3
View File
@@ -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::<nanosecond>((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::<nanosecond>((job_object_info.TotalKernelTime as f64) * 100.0);
Ok((user_time, system_time, Information::zero(), status))
} else {