From bc82bd5f235737848380491bb64dfebfe3d0548b Mon Sep 17 00:00:00 2001 From: Saurav Sharma Date: Mon, 7 Oct 2019 08:05:25 +0545 Subject: [PATCH] raise error if preparation_command length is not equal to command or 1 Signed-off-by: Saurav Sharma --- src/hyperfine/benchmark.rs | 7 ++----- src/main.rs | 10 ++++++++++ 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/hyperfine/benchmark.rs b/src/hyperfine/benchmark.rs index 3ce3e76..ba90995 100644 --- a/src/hyperfine/benchmark.rs +++ b/src/hyperfine/benchmark.rs @@ -236,11 +236,8 @@ pub fn run_benchmark( // Run init command let mut prepare_cmd = None; if let Some(values) = &options.preparation_command { - if num >= values.len() { - prepare_cmd = Some(new_command_from_get_parameter( - cmd, - &values[values.len() - 1], - )); + if values.len() == 1 { + prepare_cmd = Some(new_command_from_get_parameter(cmd, &values[0])); } else { prepare_cmd = Some(new_command_from_get_parameter(cmd, &values[num])); } diff --git a/src/main.rs b/src/main.rs index 52f795e..b0a9f94 100644 --- a/src/main.rs +++ b/src/main.rs @@ -33,6 +33,16 @@ fn run(commands: &[Command<'_>], options: &HyperfineOptions) -> io::Result 1 { + error( + "--prepare option should be provided only 1 time or N times equal to number of \ + commands to benchmark", + ); + } + } + // Run the benchmarks for (num, cmd) in commands.iter().enumerate() { timing_results.push(run_benchmark(num, cmd, shell_spawning_time, options)?);