Skip to content
Myr

Rename functions

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 7c929f7 · Browse files · 6 files+96 added−90 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

6 files+96 added−90 removed

  • other:+96 added−90 removed

6 files+96 added−90 removed

modified:src/benchmark/executor.rs+2 added-2 removed
1use std::process::{ExitStatus, Stdio};23use crate::command::Command;4use crate::execute::execute_and_measure;5use crate::options::{CmdFailureAction, CommandOutputPolicy, Options, OutputStyleOption, Shell};6use crate::output::progress_bar::get_progress_bar;6use crate::shell::execute_and_time;7use crate::timer::wallclocktimer::WallClockTimer;8use crate::util::units::Second;910use super::timing_result::TimingResult;
57 unmodified lines
68 CommandOutputPolicy::Forward => (Stdio::inherit(), Stdio::inherit()),69 };7071 let wallclock_timer = WallClockTimer::start();72 let result = execute_and_time(stdout, stderr, &command.get_command_line(), self.shell)?;72 let result = execute_and_measure(stdout, stderr, &command.get_command_line(), self.shell)?;73 let mut time_real = wallclock_timer.stop();7475 let mut time_user = result.user_time;76 let mut time_system = result.system_time;
160 unmodified lines
modified:src/util/mod.rs+1 added
1pub mod exit_code;2pub mod min_max;3pub mod number;4pub mod randomized_environment_offset;5pub mod units;
added:src/util/randomized_environment_offset.rs+8 added
1/// Returns a string with a random length. This value will be set as an environment2/// variable to account for offset effects. See [1] for more details.3///4/// [1] Mytkowicz, 2009. Producing Wrong Data Without Doing Anything Obviously Wrong!.5/// Sigplan Notices - SIGPLAN. 44. 265-276. 10.1145/1508284.1508275.6pub fn value() -> String {7 "X".repeat(rand::random::<usize>() % 4096usize)8}
added:src/execute.rs+84 added
1use std::process::{ExitStatus, Stdio};23use crate::options::Shell;4use crate::util::randomized_environment_offset;56use anyhow::{Context, Result};78/// Used to indicate the result of running a command9#[derive(Debug, Copy, Clone)]10pub struct ExecuteResult {11 /// The amount of user time the process used12 pub user_time: f64,1314 /// The amount of cpu time the process used15 pub system_time: f64,1617 /// The exit status of the process18 pub status: ExitStatus,19}2021/// Execute the given command and return a timing summary22#[cfg(not(windows))]23pub fn execute_and_measure(24 stdout: Stdio,25 stderr: Stdio,26 command: &str,27 shell: &Shell,28) -> Result<ExecuteResult> {29 let cpu_timer = crate::timer::unix_timer::CPUTimer::start();3031 let status = shell32 .command()33 .arg("-c")34 .arg(command)35 .env(36 "HYPERFINE_RANDOMIZED_ENVIRONMENT_OFFSET",37 randomized_environment_offset::value(),38 )39 .stdin(Stdio::null())40 .stdout(stdout)41 .stderr(stderr)42 .status()43 .with_context(|| format!("Failed to run command '{}'", command))?;4445 let (user_time, system_time) = cpu_timer.stop();4647 Ok(ExecuteResult {48 user_time,49 system_time,50 status,51 })52}5354/// Execute the given command and return a timing summary55#[cfg(windows)]56pub fn execute_and_measure(57 stdout: Stdio,58 stderr: Stdio,59 command: &str,60 shell: &Shell,61) -> Result<ExecuteResult> {62 let mut child = shell63 .command()64 .arg("/C")65 .arg(command)66 .env(67 "HYPERFINE_RANDOMIZED_ENVIRONMENT_OFFSET",68 randomized_environment_offset::value(),69 )70 .stdin(Stdio::null())71 .stdout(stdout)72 .stderr(stderr)73 .spawn()74 .with_context(|| format!("Failed to run command '{}'", command))?;75 let cpu_timer = crate::timer::windows_timer::CPUTimer::start_for_process(&child);76 let status = child.wait()?;7778 let (user_time, system_time) = cpu_timer.stop();79 Ok(ExecuteResult {80 user_time,81 system_time,82 status,83 })84}
modified:src/main.rs+1 added-1 removed
11 unmodified lines
12pub mod app;13pub mod benchmark;14pub mod command;15pub mod error;16pub mod execute;17pub mod export;18pub mod options;19pub mod outlier_detection;20pub mod output;21pub mod parameter;21pub mod shell;22pub mod timer;23pub mod util;2425fn run() -> Result<()> {
27 unmodified lines
deleted:src/shell.rs-87 removed
1use std::process::{ExitStatus, Stdio};23use crate::options::Shell;45use anyhow::{Context, Result};67/// Used to indicate the result of running a command8#[derive(Debug, Copy, Clone)]9pub struct ExecuteResult {10 /// The amount of user time the process used11 pub user_time: f64,1213 /// The amount of cpu time the process used14 pub system_time: f64,1516 /// The exit status of the process17 pub status: ExitStatus,18}1920fn randomized_environment_offset_value() -> String {21 "X".repeat(rand::random::<usize>() % 4096usize)22}2324/// Execute the given command and return a timing summary25#[cfg(not(windows))]26pub fn execute_and_time(27 stdout: Stdio,28 stderr: Stdio,29 command: &str,30 shell: &Shell,31) -> Result<ExecuteResult> {32 let cpu_timer = crate::timer::unix_timer::CPUTimer::start();3334 let status = shell35 .command()36 .arg("-c")37 .arg(command)38 .env(39 "HYPERFINE_RANDOMIZED_ENVIRONMENT_OFFSET",40 randomized_environment_offset_value(),41 )42 .stdin(Stdio::null())43 .stdout(stdout)44 .stderr(stderr)45 .status()46 .with_context(|| format!("Failed to run command '{}'", command))?;4748 let (user_time, system_time) = cpu_timer.stop();4950 Ok(ExecuteResult {51 user_time,52 system_time,53 status,54 })55}5657/// Execute the given command and return a timing summary58#[cfg(windows)]59pub fn execute_and_time(60 stdout: Stdio,61 stderr: Stdio,62 command: &str,63 shell: &Shell,64) -> Result<ExecuteResult> {65 let mut child = shell66 .command()67 .arg("/C")68 .arg(command)69 .env(70 "HYPERFINE_RANDOMIZED_ENVIRONMENT_OFFSET",71 randomized_environment_offset_value(),72 )73 .stdin(Stdio::null())74 .stdout(stdout)75 .stderr(stderr)76 .spawn()77 .with_context(|| format!("Failed to run command '{}'", command))?;78 let cpu_timer = crate::timer::windows_timer::CPUTimer::start_for_process(&child);79 let status = child.wait()?;8081 let (user_time, system_time) = cpu_timer.stop();82 Ok(ExecuteResult {83 user_time,84 system_time,85 status,86 })87}