From 5c634c9f2f8816857cc6754c07e1d525c3bd9b7a Mon Sep 17 00:00:00 2001 From: David Peter Date: Sun, 6 Feb 2022 20:01:41 +0100 Subject: [PATCH] Move a few modules to util --- src/benchmark/mod.rs | 4 ++-- src/benchmark/relative_speed.rs | 2 +- src/benchmark/result.rs | 2 +- src/export/asciidoc.rs | 2 +- src/export/csv.rs | 2 +- src/export/json.rs | 2 +- src/export/markdown.rs | 2 +- src/export/mod.rs | 2 +- src/main.rs | 4 +--- src/options.rs | 2 +- src/output/format.rs | 2 +- src/output/warnings.rs | 2 +- src/parameter/mod.rs | 2 +- src/parameter/range.rs | 2 +- src/timer/mod.rs | 2 +- src/timer/unix_timer.rs | 2 +- src/timer/wallclocktimer.rs | 2 +- src/timer/windows_timer.rs | 2 +- src/{ => util}/min_max.rs | 0 src/util/mod.rs | 3 +++ src/{ => util}/number.rs | 0 src/{ => util}/units.rs | 0 22 files changed, 22 insertions(+), 21 deletions(-) rename src/{ => util}/min_max.rs (100%) create mode 100644 src/util/mod.rs rename src/{ => util}/number.rs (100%) rename src/{ => util}/units.rs (100%) diff --git a/src/benchmark/mod.rs b/src/benchmark/mod.rs index ae1403a..5294368 100644 --- a/src/benchmark/mod.rs +++ b/src/benchmark/mod.rs @@ -9,7 +9,6 @@ use statistical::{mean, median, standard_deviation}; use crate::benchmark::result::BenchmarkResult; use crate::command::Command; -use crate::min_max::{max, min}; use crate::options::{CmdFailureAction, Options, OutputStyleOption, Shell}; use crate::outlier_detection::{modified_zscores, OUTLIER_THRESHOLD}; use crate::output::format::{format_duration, format_duration_unit}; @@ -18,7 +17,8 @@ use crate::output::warnings::Warnings; use crate::shell::execute_and_time; use crate::timer::wallclocktimer::WallClockTimer; use crate::timer::{TimerStart, TimerStop}; -use crate::units::Second; +use crate::util::min_max::{max, min}; +use crate::util::units::Second; use anyhow::{bail, Result}; diff --git a/src/benchmark/relative_speed.rs b/src/benchmark/relative_speed.rs index 21732af..56067d2 100644 --- a/src/benchmark/relative_speed.rs +++ b/src/benchmark/relative_speed.rs @@ -1,7 +1,7 @@ use std::cmp::Ordering; use super::result::BenchmarkResult; -use crate::units::Scalar; +use crate::util::units::Scalar; #[derive(Debug)] pub struct BenchmarkResultWithRelativeSpeed<'a> { diff --git a/src/benchmark/result.rs b/src/benchmark/result.rs index 2fa0404..0e60d8f 100644 --- a/src/benchmark/result.rs +++ b/src/benchmark/result.rs @@ -2,7 +2,7 @@ use std::collections::BTreeMap; use serde::Serialize; -use crate::units::Second; +use crate::util::units::Second; /// Set of values that will be exported. // NOTE: `serde` is used for JSON serialization, but not for CSV serialization due to the diff --git a/src/export/asciidoc.rs b/src/export/asciidoc.rs index bfa056f..5d315ee 100644 --- a/src/export/asciidoc.rs +++ b/src/export/asciidoc.rs @@ -1,7 +1,7 @@ use crate::benchmark::relative_speed::{self, BenchmarkResultWithRelativeSpeed}; use crate::benchmark::result::BenchmarkResult; use crate::output::format::format_duration_value; -use crate::units::Unit; +use crate::util::units::Unit; use super::Exporter; diff --git a/src/export/csv.rs b/src/export/csv.rs index 4c5b060..6f3532d 100644 --- a/src/export/csv.rs +++ b/src/export/csv.rs @@ -4,7 +4,7 @@ use csv::WriterBuilder; use super::Exporter; use crate::benchmark::result::BenchmarkResult; -use crate::units::Unit; +use crate::util::units::Unit; use anyhow::Result; diff --git a/src/export/json.rs b/src/export/json.rs index a0cc5d9..b5eef4d 100644 --- a/src/export/json.rs +++ b/src/export/json.rs @@ -3,7 +3,7 @@ use serde_json::to_vec_pretty; use super::Exporter; use crate::benchmark::result::BenchmarkResult; -use crate::units::Unit; +use crate::util::units::Unit; use anyhow::Result; diff --git a/src/export/markdown.rs b/src/export/markdown.rs index 65f1652..4be44fc 100644 --- a/src/export/markdown.rs +++ b/src/export/markdown.rs @@ -2,7 +2,7 @@ use super::Exporter; use crate::benchmark::relative_speed::{self, BenchmarkResultWithRelativeSpeed}; use crate::benchmark::result::BenchmarkResult; use crate::output::format::format_duration_value; -use crate::units::Unit; +use crate::util::units::Unit; use anyhow::{anyhow, Result}; diff --git a/src/export/mod.rs b/src/export/mod.rs index feb5dd4..c5bca01 100644 --- a/src/export/mod.rs +++ b/src/export/mod.rs @@ -12,7 +12,7 @@ use self::json::JsonExporter; use self::markdown::MarkdownExporter; use crate::benchmark::result::BenchmarkResult; -use crate::units::Unit; +use crate::util::units::Unit; use anyhow::{Context, Result}; use clap::ArgMatches; diff --git a/src/main.rs b/src/main.rs index 7f5def2..b90b3ba 100644 --- a/src/main.rs +++ b/src/main.rs @@ -15,15 +15,13 @@ pub mod benchmark; pub mod command; pub mod error; pub mod export; -pub mod min_max; -pub mod number; pub mod options; pub mod outlier_detection; pub mod output; pub mod parameter; pub mod shell; pub mod timer; -pub mod units; +pub mod util; pub fn write_benchmark_comparison(results: &[BenchmarkResult]) { if results.len() < 2 { diff --git a/src/options.rs b/src/options.rs index 8a51dc6..491308a 100644 --- a/src/options.rs +++ b/src/options.rs @@ -5,7 +5,7 @@ use atty::Stream; use clap::ArgMatches; use crate::error::OptionsError; -use crate::units::{Second, Unit}; +use crate::util::units::{Second, Unit}; #[cfg(not(windows))] pub const DEFAULT_SHELL: &str = "sh"; diff --git a/src/output/format.rs b/src/output/format.rs index 1e594a0..fdae0dc 100644 --- a/src/output/format.rs +++ b/src/output/format.rs @@ -1,4 +1,4 @@ -use crate::units::{Second, Unit}; +use crate::util::units::{Second, Unit}; /// Format the given duration as a string. The output-unit can be enforced by setting `unit` to /// `Some(target_unit)`. If `unit` is `None`, it will be determined automatically. diff --git a/src/output/warnings.rs b/src/output/warnings.rs index 4218a88..afaabdc 100644 --- a/src/output/warnings.rs +++ b/src/output/warnings.rs @@ -2,7 +2,7 @@ use std::fmt; use crate::benchmark::MIN_EXECUTION_TIME; use crate::output::format::format_duration; -use crate::units::Second; +use crate::util::units::Second; /// A list of all possible warnings pub enum Warnings { diff --git a/src/parameter/mod.rs b/src/parameter/mod.rs index dfccc23..f6fdb8f 100644 --- a/src/parameter/mod.rs +++ b/src/parameter/mod.rs @@ -1,4 +1,4 @@ -use crate::number::Number; +use crate::util::number::Number; pub mod range; pub mod tokenize; diff --git a/src/parameter/range.rs b/src/parameter/range.rs index 172a394..480ee0c 100644 --- a/src/parameter/range.rs +++ b/src/parameter/range.rs @@ -8,7 +8,7 @@ use rust_decimal::Decimal; use super::ParameterValue; use crate::command::Command; use crate::error::ParameterScanError; -use crate::number::Number; +use crate::util::number::Number; trait Numeric: Add diff --git a/src/timer/mod.rs b/src/timer/mod.rs index 1c3a460..45378c8 100644 --- a/src/timer/mod.rs +++ b/src/timer/mod.rs @@ -1,6 +1,6 @@ use std::process::Child; -use crate::units::Second; +use crate::util::units::Second; pub mod wallclocktimer; diff --git a/src/timer/unix_timer.rs b/src/timer/unix_timer.rs index 9069cab..ed9d39f 100644 --- a/src/timer/unix_timer.rs +++ b/src/timer/unix_timer.rs @@ -4,7 +4,7 @@ use std::mem; use std::process::Child; use crate::timer::{CPUInterval, CPUTimes, TimerStart, TimerStop}; -use crate::units::Second; +use crate::util::units::Second; pub fn get_cpu_timer() -> Box> { Box::new(CPUTimer::start()) diff --git a/src/timer/wallclocktimer.rs b/src/timer/wallclocktimer.rs index 8d1a36b..0f67f1b 100644 --- a/src/timer/wallclocktimer.rs +++ b/src/timer/wallclocktimer.rs @@ -2,7 +2,7 @@ use std::process::Child; use std::time::Instant; use crate::timer::{TimerStart, TimerStop}; -use crate::units::Second; +use crate::util::units::Second; pub struct WallClockTimer { start: Instant, diff --git a/src/timer/windows_timer.rs b/src/timer/windows_timer.rs index f8e03e6..f97c812 100644 --- a/src/timer/windows_timer.rs +++ b/src/timer/windows_timer.rs @@ -8,7 +8,7 @@ use winapi::um::processthreadsapi::GetProcessTimes; use winapi::um::winnt::HANDLE; use crate::timer::{CPUTimes, TimerStart, TimerStop}; -use crate::units::Second; +use crate::util::units::Second; const HUNDRED_NS_PER_MS: i64 = 10; diff --git a/src/min_max.rs b/src/util/min_max.rs similarity index 100% rename from src/min_max.rs rename to src/util/min_max.rs diff --git a/src/util/mod.rs b/src/util/mod.rs new file mode 100644 index 0000000..bdf1dea --- /dev/null +++ b/src/util/mod.rs @@ -0,0 +1,3 @@ +pub mod min_max; +pub mod number; +pub mod units; diff --git a/src/number.rs b/src/util/number.rs similarity index 100% rename from src/number.rs rename to src/util/number.rs diff --git a/src/units.rs b/src/util/units.rs similarity index 100% rename from src/units.rs rename to src/util/units.rs