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)?);