diff --git a/src/benchmark/executor.rs b/src/benchmark/executor.rs index 74a9d7d..ec89ace 100644 --- a/src/benchmark/executor.rs +++ b/src/benchmark/executor.rs @@ -1,9 +1,9 @@ use std::process::{ExitStatus, Stdio}; use crate::command::Command; +use crate::execute::execute_and_measure; use crate::options::{CmdFailureAction, CommandOutputPolicy, Options, OutputStyleOption, Shell}; use crate::output::progress_bar::get_progress_bar; -use crate::shell::execute_and_time; use crate::timer::wallclocktimer::WallClockTimer; use crate::util::units::Second; @@ -69,7 +69,7 @@ impl<'a> Executor for ShellExecutor<'a> { }; let wallclock_timer = WallClockTimer::start(); - let result = execute_and_time(stdout, stderr, &command.get_command_line(), self.shell)?; + let result = execute_and_measure(stdout, stderr, &command.get_command_line(), self.shell)?; let mut time_real = wallclock_timer.stop(); let mut time_user = result.user_time; diff --git a/src/shell.rs b/src/execute.rs similarity index 88% rename from src/shell.rs rename to src/execute.rs index b5e1e85..7c1bf8f 100644 --- a/src/shell.rs +++ b/src/execute.rs @@ -1,6 +1,7 @@ use std::process::{ExitStatus, Stdio}; use crate::options::Shell; +use crate::util::randomized_environment_offset; use anyhow::{Context, Result}; @@ -17,13 +18,9 @@ pub struct ExecuteResult { pub status: ExitStatus, } -fn randomized_environment_offset_value() -> String { - "X".repeat(rand::random::() % 4096usize) -} - /// Execute the given command and return a timing summary #[cfg(not(windows))] -pub fn execute_and_time( +pub fn execute_and_measure( stdout: Stdio, stderr: Stdio, command: &str, @@ -37,7 +34,7 @@ pub fn execute_and_time( .arg(command) .env( "HYPERFINE_RANDOMIZED_ENVIRONMENT_OFFSET", - randomized_environment_offset_value(), + randomized_environment_offset::value(), ) .stdin(Stdio::null()) .stdout(stdout) @@ -56,7 +53,7 @@ pub fn execute_and_time( /// Execute the given command and return a timing summary #[cfg(windows)] -pub fn execute_and_time( +pub fn execute_and_measure( stdout: Stdio, stderr: Stdio, command: &str, @@ -68,7 +65,7 @@ pub fn execute_and_time( .arg(command) .env( "HYPERFINE_RANDOMIZED_ENVIRONMENT_OFFSET", - randomized_environment_offset_value(), + randomized_environment_offset::value(), ) .stdin(Stdio::null()) .stdout(stdout) diff --git a/src/main.rs b/src/main.rs index 319fab3..9b58f3e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -13,12 +13,12 @@ pub mod app; pub mod benchmark; pub mod command; pub mod error; +pub mod execute; pub mod export; pub mod options; pub mod outlier_detection; pub mod output; pub mod parameter; -pub mod shell; pub mod timer; pub mod util; diff --git a/src/util/mod.rs b/src/util/mod.rs index 8f5e063..de9e168 100644 --- a/src/util/mod.rs +++ b/src/util/mod.rs @@ -1,4 +1,5 @@ pub mod exit_code; pub mod min_max; pub mod number; +pub mod randomized_environment_offset; pub mod units; diff --git a/src/util/randomized_environment_offset.rs b/src/util/randomized_environment_offset.rs new file mode 100644 index 0000000..d445b96 --- /dev/null +++ b/src/util/randomized_environment_offset.rs @@ -0,0 +1,8 @@ +/// Returns a string with a random length. This value will be set as an environment +/// variable to account for offset effects. See [1] for more details. +/// +/// [1] Mytkowicz, 2009. Producing Wrong Data Without Doing Anything Obviously Wrong!. +/// Sigplan Notices - SIGPLAN. 44. 265-276. 10.1145/1508284.1508275. +pub fn value() -> String { + "X".repeat(rand::random::() % 4096usize) +}