Remove alternative constructors
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 f57c4e6 · Browse files · 8 files·+112 added−113 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
8 files+112 added−113 removed
- other:+112 added−113 removed
Provenance
- Commit
3494c8a- Tree
13a97bc- Author
David Peter <sharkdp@users.noreply.github.com>- Committer
David Peter <mail@david-peter.de>- Parent
f57c4e6
8 files changed+112 added−113 removed
modified:src/benchmark/executor.rs+4 added-6 removed
7 unmodified lines8 use crate::options::{9 CmdFailureAction, CommandInputPolicy, CommandOutputPolicy, Options, OutputStyleOption, Shell,10 };11 use crate::output::progress_bar::get_progress_bar;12-use crate::quantity::Information;13-use crate::quantity::InformationQuantity;14-use crate::quantity::{Time, TimeQuantity};12+use crate::quantity::{byte, second, Information, Time, TimeQuantity};13 use crate::timer::execute_and_measure;14 use crate::util::randomized_environment_offset;15 16 use anyhow::{bail, Context, Result};296 unmodified lines313 }314 315 fn extract_time<S: AsRef<str>>(sleep_command: S) -> Time {316 assert!(sleep_command.as_ref().starts_with("sleep "));319- Time::from_seconds(317+ Time::new::<second>(318 sleep_command319 .as_ref()320 .trim_start_matches("sleep ")321 .parse::<f64>()25 unmodified lines347 Ok(Measurement {348 time_wall_clock: Self::extract_time(command.get_command_line()),349 time_user: Time::zero(),350 time_system: Time::zero(),353- peak_memory_usage: Information::from_bytes(0),351+ peak_memory_usage: Information::new::<byte>(0),352 exit_status,353 })354 }355 12 unmodified lines368 #[test]369 fn test_mock_executor_extract_time() {370 assert_eq!(371 MockExecutor::extract_time("sleep 0.1"),374- Time::from_seconds(0.1)372+ Time::new::<second>(0.1)373 );374 }modified:src/benchmark/relative_speed.rs+3 added-2 removed
152 unmodified lines153 fn create_result(name: &str, mean: f64) -> BenchmarkResult {154 use std::collections::BTreeMap;155 156 use crate::benchmark::measurement::{Measurement, Measurements};157+ use crate::quantity::second;158 159 BenchmarkResult {160 command: name.into(),161 measurements: Measurements {162 measurements: vec![Measurement {162- time_wall_clock: Time::from_seconds(mean),163- time_user: Time::from_seconds(mean),163+ time_wall_clock: Time::new::<second>(mean),164+ time_user: Time::new::<second>(mean),165 ..Default::default()166 }],167 },168 parameters: BTreeMap::new(),67 unmodified linesmodified:src/export/csv.rs+19 added-19 removed
67 unmodified lines68 #[test]69 fn test_csv() {70 use crate::benchmark::benchmark_result::Parameter;71 use crate::benchmark::measurement::{Measurement, Measurements};72- use crate::quantity::{Information, InformationQuantity, Time, TimeQuantity};72+ use crate::quantity::{byte, Information, 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: Time::from_seconds(7.0),85- time_user: Time::from_seconds(7.0),84+ time_wall_clock: Time::new::<second>(7.0),85+ time_user: Time::new::<second>(7.0),86 time_system: Time::zero(),87- peak_memory_usage: Information::from_bytes(1024),87+ peak_memory_usage: Information::new::<byte>(1024),88 exit_status: ExitStatus::default(),89 },90 Measurement {91- time_wall_clock: Time::from_seconds(8.0),92- time_user: Time::from_seconds(8.0),91+ time_wall_clock: Time::new::<second>(8.0),92+ time_user: Time::new::<second>(8.0),93 time_system: Time::zero(),94- peak_memory_usage: Information::from_bytes(1024),94+ peak_memory_usage: Information::new::<byte>(1024),95 exit_status: ExitStatus::default(),96 },97 Measurement {98- time_wall_clock: Time::from_seconds(12.0),99- time_user: Time::from_seconds(12.0),98+ time_wall_clock: Time::new::<second>(12.0),99+ time_user: Time::new::<second>(12.0),100 time_system: Time::zero(),101- peak_memory_usage: Information::from_bytes(1024),101+ peak_memory_usage: Information::new::<byte>(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: Time::from_seconds(17.0),129- time_user: Time::from_seconds(17.0),128+ time_wall_clock: Time::new::<second>(17.0),129+ time_user: Time::new::<second>(17.0),130 time_system: Time::zero(),131- peak_memory_usage: Information::from_bytes(1024),131+ peak_memory_usage: Information::new::<byte>(1024),132 exit_status: ExitStatus::default(),133 },134 Measurement {135- time_wall_clock: Time::from_seconds(18.0),136- time_user: Time::from_seconds(18.0),135+ time_wall_clock: Time::new::<second>(18.0),136+ time_user: Time::new::<second>(18.0),137 time_system: Time::zero(),138- peak_memory_usage: Information::from_bytes(1024),138+ peak_memory_usage: Information::new::<byte>(1024),139 exit_status: ExitStatus::default(),140 },141 Measurement {142- time_wall_clock: Time::from_seconds(19.0),143- time_user: Time::from_seconds(19.0),142+ time_wall_clock: Time::new::<second>(19.0),143+ time_user: Time::new::<second>(19.0),144 time_system: Time::zero(),145- peak_memory_usage: Information::from_bytes(1024),145+ peak_memory_usage: Information::new::<byte>(1024),146 exit_status: ExitStatus::default(),147 },148 ]),149 parameters: {33 unmodified linesmodified:src/export/tests.rs+73 added-73 removed
1 unmodified line2 use crate::benchmark::benchmark_result::BenchmarkResult;3 use crate::benchmark::measurement::{Measurement, Measurements};4 use crate::export::asciidoc::AsciidocExporter;5 use crate::export::orgmode::OrgmodeExporter;6-use crate::quantity::{Information, InformationQuantity, Time, TimeQuantity};6+use crate::quantity::{byte, second, Information, Time, TimeQuantity};7 use crate::util::units::TimeUnit;8 use crate::{export::markdown::MarkdownExporter, options::SortOrder};9 use std::collections::BTreeMap;10 use std::process::ExitStatus;19 unmodified lines30 BenchmarkResult {31 command: String::from("sleep 0.1"),32 measurements: Measurements::new(vec![33 Measurement {34- time_wall_clock: Time::from_seconds(0.09),35- time_user: Time::from_seconds(0.09),34+ time_wall_clock: Time::new::<second>(0.09),35+ time_user: Time::new::<second>(0.09),36 time_system: Time::zero(),37- peak_memory_usage: Information::from_bytes(1024),37+ peak_memory_usage: Information::new::<byte>(1024),38 exit_status: ExitStatus::default(),39 },40 Measurement {41- time_wall_clock: Time::from_seconds(0.10),42- time_user: Time::from_seconds(0.10),41+ time_wall_clock: Time::new::<second>(0.10),42+ time_user: Time::new::<second>(0.10),43 time_system: Time::zero(),44- peak_memory_usage: Information::from_bytes(1024),44+ peak_memory_usage: Information::new::<byte>(1024),45 exit_status: ExitStatus::default(),46 },47 Measurement {48- time_wall_clock: Time::from_seconds(0.14),49- time_user: Time::from_seconds(0.14),48+ time_wall_clock: Time::new::<second>(0.14),49+ time_user: Time::new::<second>(0.14),50 time_system: Time::zero(),51- peak_memory_usage: Information::from_bytes(1024),51+ peak_memory_usage: Information::new::<byte>(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: Time::from_seconds(2.0),62- time_user: Time::from_seconds(2.0),61+ time_wall_clock: Time::new::<second>(2.0),62+ time_user: Time::new::<second>(2.0),63 time_system: Time::zero(),64- peak_memory_usage: Information::from_bytes(1024),64+ peak_memory_usage: Information::new::<byte>(1024),65 exit_status: ExitStatus::default(),66 },67 Measurement {68- time_wall_clock: Time::from_seconds(3.0),69- time_user: Time::from_seconds(3.0),68+ time_wall_clock: Time::new::<second>(3.0),69+ time_user: Time::new::<second>(3.0),70 time_system: Time::zero(),71- peak_memory_usage: Information::from_bytes(1024),71+ peak_memory_usage: Information::new::<byte>(1024),72 exit_status: ExitStatus::default(),73 },74 Measurement {75- time_wall_clock: Time::from_seconds(4.0),76- time_user: Time::from_seconds(4.0),75+ time_wall_clock: Time::new::<second>(4.0),76+ time_user: Time::new::<second>(4.0),77 time_system: Time::zero(),78- peak_memory_usage: Information::from_bytes(1024),78+ peak_memory_usage: Information::new::<byte>(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: Time::from_seconds(2.1),134- time_user: Time::from_seconds(2.1),133+ time_wall_clock: Time::new::<second>(2.1),134+ time_user: Time::new::<second>(2.1),135 time_system: Time::zero(),136- peak_memory_usage: Information::from_bytes(1024),136+ peak_memory_usage: Information::new::<byte>(1024),137 exit_status: ExitStatus::default(),138 },139 Measurement {140- time_wall_clock: Time::from_seconds(2.2),141- time_user: Time::from_seconds(2.2),140+ time_wall_clock: Time::new::<second>(2.2),141+ time_user: Time::new::<second>(2.2),142 time_system: Time::zero(),143- peak_memory_usage: Information::from_bytes(1024),143+ peak_memory_usage: Information::new::<byte>(1024),144 exit_status: ExitStatus::default(),145 },146 Measurement {147- time_wall_clock: Time::from_seconds(2.3),148- time_user: Time::from_seconds(2.3),147+ time_wall_clock: Time::new::<second>(2.3),148+ time_user: Time::new::<second>(2.3),149 time_system: Time::zero(),150- peak_memory_usage: Information::from_bytes(1024),150+ peak_memory_usage: Information::new::<byte>(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: Time::from_seconds(0.1),161- time_user: Time::from_seconds(0.1),160+ time_wall_clock: Time::new::<second>(0.1),161+ time_user: Time::new::<second>(0.1),162 time_system: Time::zero(),163- peak_memory_usage: Information::from_bytes(1024),163+ peak_memory_usage: Information::new::<byte>(1024),164 exit_status: ExitStatus::default(),165 },166 Measurement {167- time_wall_clock: Time::from_seconds(0.2),168- time_user: Time::from_seconds(0.2),167+ time_wall_clock: Time::new::<second>(0.2),168+ time_user: Time::new::<second>(0.2),169 time_system: Time::zero(),170- peak_memory_usage: Information::from_bytes(1024),170+ peak_memory_usage: Information::new::<byte>(1024),171 exit_status: ExitStatus::default(),172 },173 Measurement {174- time_wall_clock: Time::from_seconds(0.3),175- time_user: Time::from_seconds(0.3),174+ time_wall_clock: Time::new::<second>(0.3),175+ time_user: Time::new::<second>(0.3),176 time_system: Time::zero(),177- peak_memory_usage: Information::from_bytes(1024),177+ peak_memory_usage: Information::new::<byte>(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: Time::from_seconds(2.1),233- time_user: Time::from_seconds(2.1),232+ time_wall_clock: Time::new::<second>(2.1),233+ time_user: Time::new::<second>(2.1),234 time_system: Time::zero(),235- peak_memory_usage: Information::from_bytes(1024),235+ peak_memory_usage: Information::new::<byte>(1024),236 exit_status: ExitStatus::default(),237 },238 Measurement {239- time_wall_clock: Time::from_seconds(2.2),240- time_user: Time::from_seconds(2.2),239+ time_wall_clock: Time::new::<second>(2.2),240+ time_user: Time::new::<second>(2.2),241 time_system: Time::zero(),242- peak_memory_usage: Information::from_bytes(1024),242+ peak_memory_usage: Information::new::<byte>(1024),243 exit_status: ExitStatus::default(),244 },245 Measurement {246- time_wall_clock: Time::from_seconds(2.3),247- time_user: Time::from_seconds(2.3),246+ time_wall_clock: Time::new::<second>(2.3),247+ time_user: Time::new::<second>(2.3),248 time_system: Time::zero(),249- peak_memory_usage: Information::from_bytes(1024),249+ peak_memory_usage: Information::new::<byte>(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: Time::from_seconds(0.1),260- time_user: Time::from_seconds(0.1),259+ time_wall_clock: Time::new::<second>(0.1),260+ time_user: Time::new::<second>(0.1),261 time_system: Time::zero(),262- peak_memory_usage: Information::from_bytes(1024),262+ peak_memory_usage: Information::new::<byte>(1024),263 exit_status: ExitStatus::default(),264 },265 Measurement {266- time_wall_clock: Time::from_seconds(0.2),267- time_user: Time::from_seconds(0.2),266+ time_wall_clock: Time::new::<second>(0.2),267+ time_user: Time::new::<second>(0.2),268 time_system: Time::zero(),269- peak_memory_usage: Information::from_bytes(1024),269+ peak_memory_usage: Information::new::<byte>(1024),270 exit_status: ExitStatus::default(),271 },272 Measurement {273- time_wall_clock: Time::from_seconds(0.3),274- time_user: Time::from_seconds(0.3),273+ time_wall_clock: Time::new::<second>(0.3),274+ time_user: Time::new::<second>(0.3),275 time_system: Time::zero(),276- peak_memory_usage: Information::from_bytes(1024),276+ peak_memory_usage: Information::new::<byte>(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: Time::from_seconds(2.01),331- time_user: Time::from_seconds(2.01),330+ time_wall_clock: Time::new::<second>(2.01),331+ time_user: Time::new::<second>(2.01),332 time_system: Time::zero(),333- peak_memory_usage: Information::from_bytes(1024),333+ peak_memory_usage: Information::new::<byte>(1024),334 exit_status: ExitStatus::default(),335 },336 Measurement {337- time_wall_clock: Time::from_seconds(2.02),338- time_user: Time::from_seconds(2.02),337+ time_wall_clock: Time::new::<second>(2.02),338+ time_user: Time::new::<second>(2.02),339 time_system: Time::zero(),340- peak_memory_usage: Information::from_bytes(1024),340+ peak_memory_usage: Information::new::<byte>(1024),341 exit_status: ExitStatus::default(),342 },343 Measurement {344- time_wall_clock: Time::from_seconds(2.03),345- time_user: Time::from_seconds(2.03),344+ time_wall_clock: Time::new::<second>(2.03),345+ time_user: Time::new::<second>(2.03),346 time_system: Time::zero(),347- peak_memory_usage: Information::from_bytes(1024),347+ peak_memory_usage: Information::new::<byte>(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: Time::from_seconds(0.11),358- time_user: Time::from_seconds(0.11),357+ time_wall_clock: Time::new::<second>(0.11),358+ time_user: Time::new::<second>(0.11),359 time_system: Time::zero(),360- peak_memory_usage: Information::from_bytes(1024),360+ peak_memory_usage: Information::new::<byte>(1024),361 exit_status: ExitStatus::default(),362 },363 Measurement {364- time_wall_clock: Time::from_seconds(0.12),365- time_user: Time::from_seconds(0.12),364+ time_wall_clock: Time::new::<second>(0.12),365+ time_user: Time::new::<second>(0.12),366 time_system: Time::zero(),367- peak_memory_usage: Information::from_bytes(1024),367+ peak_memory_usage: Information::new::<byte>(1024),368 exit_status: ExitStatus::default(),369 },370 Measurement {371- time_wall_clock: Time::from_seconds(0.13),372- time_user: Time::from_seconds(0.13),371+ time_wall_clock: Time::new::<second>(0.13),372+ time_user: Time::new::<second>(0.13),373 time_system: Time::zero(),374- peak_memory_usage: Information::from_bytes(1024),374+ peak_memory_usage: Information::new::<byte>(1024),375 exit_status: ExitStatus::default(),376 },377 ]),378 parameters: BTreeMap::new(),40 unmodified linesmodified:src/timer/unix_timer.rs+4 added-4 removed
6 unmodified lines7 use std::process::{Child, ExitStatus};8 9 use anyhow::Result;10 11-use crate::quantity::{Information, InformationQuantity, Time, TimeQuantity};11+use crate::quantity::{byte, kibibyte, microsecond, second, Information, Time};12 13 #[derive(Debug, Copy, Clone)]14 struct ResourceUsage {15 /// Total amount of time spent executing in user mode10 unmodified lines26 fn convert_timeval(tv: libc::timeval) -> Time {27 let sec = tv.tv_sec as f64;28 let usec = tv.tv_usec as f64;29 30- Time::from_seconds(sec) + Time::from_microseconds(usec)30+ Time::new::<second>(sec) + Time::new::<microsecond>(usec)31 }32 33 #[allow(clippy::useless_conversion)]34 fn wait4(mut child: Child) -> io::Result<(ExitStatus, ResourceUsage)> {11 unmodified lines46 let rusage = unsafe { rusage.assume_init() };47 48 let memory_usage_byte = if cfg!(target_os = "macos") || cfg!(target_os = "ios") {49 // Linux and *BSD return the value in KibiBytes, Darwin flavors in bytes50- Information::from_bytes(u64::try_from(rusage.ru_maxrss).unwrap_or(0))50+ Information::new::<byte>(u64::try_from(rusage.ru_maxrss).unwrap_or(0))51 } else {52- Information::from_kibibytes(u64::try_from(rusage.ru_maxrss).unwrap_or(0))52+ Information::new::<kibibyte>(u64::try_from(rusage.ru_maxrss).unwrap_or(0))53 };54 55 Ok((56 ExitStatus::from_raw(status),26 unmodified linesmodified:src/timer/wall_clock_timer.rs+3 added-3 removed
1 use std::time::Instant;2 3-use crate::quantity::{Time, TimeQuantity};3+use crate::quantity::{nanosecond, second, Time};4 5 pub struct WallClockTimer {6 start: Instant,7 }7 unmodified lines15 16 pub fn stop(&self) -> Time {17 let duration = self.start.elapsed();18 19- Time::from_seconds(duration.as_secs() as f64)20- + Time::from_nanoseconds(duration.subsec_nanos() as f64)19+ Time::new::<second>(duration.as_secs() as f64)20+ + Time::new::<nanosecond>(duration.subsec_nanos() as f64)21 }22 }modified:src/timer/windows_timer.rs+3 added-3 removed
28 unmodified lines29 System::LibraryLoader::{GetModuleHandleW, GetProcAddress},30 },31 };32 33-use crate::quantity::{Information, InformationQuantity, Time, TimeQuantity};33+use crate::quantity::{nanosecond, Information, InformationQuantity, Time};34 35 #[cfg(not(feature = "windows_process_extensions_main_thread_handle"))]36 #[allow(non_upper_case_globals)]37 static NtResumeProcess: Lazy<unsafe extern "system" fn(process_handle: HANDLE) -> NTSTATUS> =69 unmodified lines107 108 // The `TotalUserTime` is "The total amount of user-mode execution time for109 // all active processes associated with the job, as well as all terminated processes no110 // longer associated with the job, in 100-nanosecond ticks."111- let user_time = Time::from_nanoseconds((job_object_info.TotalUserTime as f64) * 100.0);111+ let user_time = Time::new::<nanosecond>((job_object_info.TotalUserTime as f64) * 100.0);112 113 // The `TotalKernelTime` is "The total amount of kernel-mode execution time114 // for all active processes associated with the job, as well as all terminated115 // processes no longer associated with the job, in 100-nanosecond ticks."116 let system_time =117- Time::from_nanoseconds((job_object_info.TotalKernelTime as f64) * 100.0);117+ Time::new::<nanosecond>((job_object_info.TotalKernelTime as f64) * 100.0);118 119 Ok((user_time, system_time, Information::zero(), status))120 } else {121 Ok((Time::zero(), Time::zero(), Information::zero(), status))10 unmodified linesmodified:src/options.rs+3 added-3 removed
7 unmodified lines8 use clap::ArgMatches;9 10 use crate::command::Commands;11 use crate::error::OptionsError;12-use crate::quantity::{Time, TimeQuantity};12+use crate::quantity::{second, Time};13 use crate::util::units::TimeUnit;14 15 use anyhow::Result;16 239 unmodified lines256 fn default() -> Options {257 Options {258 run_bounds: RunBounds::default(),259 warmup_count: 0,260- min_benchmarking_time: Time::from_seconds(3.0),260+ min_benchmarking_time: Time::new::<second>(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 = Time::from_seconds(446+ options.min_benchmarking_time = Time::new::<second>(447 time.parse::<f64>()448 .map_err(|e| OptionsError::FloatParsingError("min-benchmarking-time", e))?,449 );450 }127 unmodified lines