mirror of
https://github.com/sharkdp/hyperfine.git
synced 2026-11-01 08:50:19 +00:00
Further simplify execute_and_measure
This commit is contained in:
1 parent
0ffc6d7cc0
commit
e1da8ba00f
2 files changed
+8
-10
No files matched your search
@@ -9,7 +9,7 @@ use crate::util::units::Second;
|
|||||||
|
|
||||||
use super::timing_result::TimingResult;
|
use super::timing_result::TimingResult;
|
||||||
|
|
||||||
use anyhow::{bail, Result};
|
use anyhow::{bail, Context, Result};
|
||||||
use statistical::mean;
|
use statistical::mean;
|
||||||
|
|
||||||
pub trait Executor {
|
pub trait Executor {
|
||||||
@@ -79,10 +79,10 @@ impl<'a> Executor for ShellExecutor<'a> {
|
|||||||
.stdin(Stdio::null())
|
.stdin(Stdio::null())
|
||||||
.stdout(stdout)
|
.stdout(stdout)
|
||||||
.stderr(stderr);
|
.stderr(stderr);
|
||||||
let error_message = format!("Failed to run command '{}'", command.get_command_line());
|
|
||||||
|
|
||||||
let wallclock_timer = WallClockTimer::start();
|
let wallclock_timer = WallClockTimer::start();
|
||||||
let result = execute_and_measure(command_builder, &error_message)?;
|
let result = execute_and_measure(command_builder)
|
||||||
|
.with_context(|| format!("Failed to run command '{}'", command.get_command_line()))?;
|
||||||
let mut time_real = wallclock_timer.stop();
|
let mut time_real = wallclock_timer.stop();
|
||||||
|
|
||||||
let mut time_user = result.user_time;
|
let mut time_user = result.user_time;
|
||||||
|
|||||||
+5
-7
@@ -10,7 +10,7 @@ use crate::util::units::Second;
|
|||||||
|
|
||||||
use std::process::{Command, ExitStatus};
|
use std::process::{Command, ExitStatus};
|
||||||
|
|
||||||
use anyhow::{Context, Result};
|
use anyhow::Result;
|
||||||
|
|
||||||
#[derive(Debug, Copy, Clone)]
|
#[derive(Debug, Copy, Clone)]
|
||||||
struct CPUTimes {
|
struct CPUTimes {
|
||||||
@@ -36,11 +36,9 @@ pub struct ExecuteResult {
|
|||||||
|
|
||||||
/// Execute the given command and return a timing summary
|
/// Execute the given command and return a timing summary
|
||||||
#[cfg(not(windows))]
|
#[cfg(not(windows))]
|
||||||
pub fn execute_and_measure(mut command: Command, error_message: &str) -> Result<ExecuteResult> {
|
pub fn execute_and_measure(mut command: Command) -> Result<ExecuteResult> {
|
||||||
let cpu_timer = self::unix_timer::CPUTimer::start();
|
let cpu_timer = self::unix_timer::CPUTimer::start();
|
||||||
let status = command
|
let status = command.status()?;
|
||||||
.status()
|
|
||||||
.with_context(|| error_message.to_string())?;
|
|
||||||
let (user_time, system_time) = cpu_timer.stop();
|
let (user_time, system_time) = cpu_timer.stop();
|
||||||
|
|
||||||
Ok(ExecuteResult {
|
Ok(ExecuteResult {
|
||||||
@@ -52,8 +50,8 @@ pub fn execute_and_measure(mut command: Command, error_message: &str) -> Result<
|
|||||||
|
|
||||||
/// Execute the given command and return a timing summary
|
/// Execute the given command and return a timing summary
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
pub fn execute_and_measure(mut command: Command, error_message: &str) -> Result<ExecuteResult> {
|
pub fn execute_and_measure(mut command: Command) -> Result<ExecuteResult> {
|
||||||
let mut child = command.spawn().with_context(|| error_message.to_string())?;
|
let mut child = command.spawn()?;
|
||||||
let cpu_timer = self::windows_timer::CPUTimer::start_for_process(&child);
|
let cpu_timer = self::windows_timer::CPUTimer::start_for_process(&child);
|
||||||
let status = child.wait()?;
|
let status = child.wait()?;
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user