mirror of
https://github.com/sharkdp/hyperfine.git
synced 2026-10-28 16:18:57 +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 anyhow::{bail, Result};
|
||||
use anyhow::{bail, Context, Result};
|
||||
use statistical::mean;
|
||||
|
||||
pub trait Executor {
|
||||
@@ -79,10 +79,10 @@ impl<'a> Executor for ShellExecutor<'a> {
|
||||
.stdin(Stdio::null())
|
||||
.stdout(stdout)
|
||||
.stderr(stderr);
|
||||
let error_message = format!("Failed to run command '{}'", command.get_command_line());
|
||||
|
||||
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_user = result.user_time;
|
||||
|
||||
+5
-7
@@ -10,7 +10,7 @@ use crate::util::units::Second;
|
||||
|
||||
use std::process::{Command, ExitStatus};
|
||||
|
||||
use anyhow::{Context, Result};
|
||||
use anyhow::Result;
|
||||
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
struct CPUTimes {
|
||||
@@ -36,11 +36,9 @@ pub struct ExecuteResult {
|
||||
|
||||
/// Execute the given command and return a timing summary
|
||||
#[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 status = command
|
||||
.status()
|
||||
.with_context(|| error_message.to_string())?;
|
||||
let status = command.status()?;
|
||||
let (user_time, system_time) = cpu_timer.stop();
|
||||
|
||||
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
|
||||
#[cfg(windows)]
|
||||
pub fn execute_and_measure(mut command: Command, error_message: &str) -> Result<ExecuteResult> {
|
||||
let mut child = command.spawn().with_context(|| error_message.to_string())?;
|
||||
pub fn execute_and_measure(mut command: Command) -> Result<ExecuteResult> {
|
||||
let mut child = command.spawn()?;
|
||||
let cpu_timer = self::windows_timer::CPUTimer::start_for_process(&child);
|
||||
let status = child.wait()?;
|
||||
|
||||
|
||||
Reference in new issue
Block a user