Skip to content
Myr

Use String instead of NumericType for paramater in Command

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

authored by Hasan Ibraheem · committed by David Peter · parent 7fe65c5 · Browse files · 3 files+11 added−11 removed
This commit

State

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

Diff stats

3 files+11 added−11 removed

  • other:+11 added−11 removed

3 files+11 added−11 removed

modified:src/hyperfine/benchmark.rs+3 added-3 removed
223 unmodified lines
224 } else {225 &values[num]226 };227 match cmd.get_parameter() {228 Some((param, value)) => Command::new_parametrized(preparation_command, param, value),228 Some((param, value)) => Command::new_parametrized(preparation_command, param, value.clone()),229 None => Command::new(preparation_command),230 }231 });232
187 unmodified lines
420 options421 .cleanup_command422 .as_ref()423 .map(|cleanup_command| match cmd.get_parameter() {424 Some((param, value)) => Command::new_parametrized(cleanup_command, param, value),424 Some((param, value)) => Command::new_parametrized(cleanup_command, param, value.clone()),425 None => Command::new(cleanup_command),426 });427 run_cleanup_command(&options.shell, &cleanup_cmd, options.show_output)?;428
6 unmodified lines
435 system_mean,436 t_min,437 t_max,438 times_real,439 cmd.get_parameter().map(|p| p.1),439 cmd.get_parameter().as_ref().map(|p| p.1.clone()),440 ))441}
modified:src/hyperfine/parameter_range.rs+1 added-1 removed
90 unmodified lines
91 let mut commands = vec![];9293 for value in param_range {94 for cmd in &command_strings {95 commands.push(Command::new_parametrized(cmd, param_name, value.into()));95 commands.push(Command::new_parametrized(cmd, param_name, value.into().to_string()));96 }97 }98 Ok(commands)99}
80 unmodified lines
modified:src/hyperfine/types.rs+7 added-7 removed
44 unmodified lines
45 /// The command that should be executed (without parameter substitution)46 expression: &'a str,4748 /// A possible parameter value.49 parameter: Option<(&'a str, NumericType)>,49 parameter: Option<(&'a str, String)>,50}5152impl<'a> Command<'a> {53 pub fn new(expression: &'a str) -> Command<'a> {
5 unmodified lines
5960 pub fn new_parametrized(61 expression: &'a str,62 parameter: &'a str,63 value: NumericType,63 value: String,64 ) -> Command<'a> {65 Command {66 expression,67 parameter: Some((parameter, value)),68 }69 }7071 pub fn get_shell_command(&self) -> String {72 match self.parameter {72 match &self.parameter {73 Some((param_name, param_value)) => self.expression.replace(74 &format!("{{{param_name}}}", param_name = param_name),75 &param_value.to_string(),76 ),77 None => self.expression.into(),78 }79 }8081 pub fn get_parameter(&self) -> Option<(&'a str, NumericType)> {82 self.parameter81 pub fn get_parameter(&self) -> &Option<(&'a str, String)> {82 &self.parameter83 }84}8586impl<'a> fmt::Display for Command<'a> {
128 unmodified lines
215 pub times: Option<Vec<Second>>,216217 /// Any parameter used218 #[serde(skip_serializing_if = "Option::is_none")]219 pub parameter: Option<NumericType>,219 pub parameter: Option<String>,220}221222impl BenchmarkResult {223 /// Create a new entry with the given values.
6 unmodified lines
230 system: Second,231 min: Second,232 max: Second,233 times: Vec<Second>,234 parameter: Option<NumericType>,234 parameter: Option<String>,235 ) -> Self {236 BenchmarkResult {237 command,238 mean,
11 unmodified lines