mirror of
https://github.com/sharkdp/hyperfine.git
synced 2026-11-02 09:01:25 +00:00
Implement '--parameter-range var min max', see #19
This commit is contained in:
1 parent
3966bf05c1
commit
e862cf8567
5 files changed
+151
-12
No files matched your search
+45
-2
@@ -1,9 +1,52 @@
|
||||
/// The types module contains common internal types for the application.
|
||||
///
|
||||
/// This module contains common internal types.
|
||||
|
||||
use std::fmt;
|
||||
|
||||
/// Type alias for unit of time
|
||||
pub type Second = f64;
|
||||
|
||||
/// A command that should be benchmarked.
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Command<'a> {
|
||||
/// The command that should be executed (without parameter substitution)
|
||||
expression: &'a str,
|
||||
|
||||
/// A possible parameter value.
|
||||
parameter: Option<(&'a str, i32)>,
|
||||
}
|
||||
|
||||
impl<'a> Command<'a> {
|
||||
pub fn new(expression: &'a str) -> Command<'a> {
|
||||
Command {
|
||||
expression: expression,
|
||||
parameter: None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn new_parametrized(expression: &'a str, parameter: &'a str, value: i32) -> Command<'a> {
|
||||
Command {
|
||||
expression: expression,
|
||||
parameter: Some((parameter, value)),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_shell_command(&self) -> String {
|
||||
match self.parameter {
|
||||
Some((param_name, param_value)) => self.expression.replace(
|
||||
&format!("{{{param_name}}}", param_name = param_name),
|
||||
¶m_value.to_string(),
|
||||
),
|
||||
None => self.expression.into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> fmt::Display for Command<'a> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(f, "{}", self.get_shell_command())
|
||||
}
|
||||
}
|
||||
|
||||
/// Action to take when an executed command fails.
|
||||
#[derive(Debug, Clone, Copy, PartialEq)]
|
||||
pub enum CmdFailureAction {
|
||||
|
||||
Reference in new issue
Block a user