Repository: sharkdp/hyperfine
File: src/hyperfine/benchmark.rs (Rust)

Code before:
            "Performing warmup runs",
            options.output_style,
        );

        for _ in 0..options.warmup_count {
            let _ = time_shell_command(
                &options.shell,
                cmd,
                options.show_output,
                options.failure_action,
                None,
            )?;
            progress_bar.inc(1);
        }
        progress_bar.finish_and_clear();
    }

    // Set up progress bar (and spinner for initial measurement)
    let progress_bar = get_progress_bar(
        options.runs.min,
        "Initial time measurement",
        options.output_style,
    );

    // Run init command
    let mut prepare_cmd = None;
    if let Some(values) = &options.preparation_command {
        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]));
        }
    };
    let prepare_res = run_preparation_command(&options.shell, &prepare_cmd, options.show_output)?;

    // Initial timing run
    let (res, success) = time_shell_command(
        &options.shell,
        cmd,
        options.show_output,
        options.failure_action,
        Some(shell_spawning_time),
    )?;

    // Determine number of benchmark runs
    let runs_in_min_time = (options.min_time_sec
        / (res.time_real + prepare_res.time_real + shell_spawning_time.time_real))
        as u64;

    let count = {
        let min = cmp::max(runs_in_min_time, options.runs.min);

Review comment (suggestion):
instead of using `mut` here, I would prefer
``` rust
let prepare_cmd = if … {
  …
} else {
  None
};
```
or (even better) a `.map` over the `options.preparation_command`, like it was before.

Code after:
            "Performing warmup runs",
            options.output_style,
        );

        for _ in 0..options.warmup_count {
            let _ = time_shell_command(
                &options.shell,
                cmd,
                options.show_output,
                options.failure_action,
                None,
            )?;
            progress_bar.inc(1);
        }
        progress_bar.finish_and_clear();
    }

    // Set up progress bar (and spinner for initial measurement)
    let progress_bar = get_progress_bar(
        options.runs.min,
        "Initial time measurement",
        options.output_style,
    );

    // Run init command
    let prepare_cmd = options.preparation_command.as_ref().map(|values| {
        let preparation_command = if values.len() == 1 {
            &values[0]
        } else {
            &values[num]
        };
        match cmd.get_parameter() {
            Some((param, value)) => Command::new_parametrized(preparation_command, param, value),
            None => Command::new(preparation_command),
        }
    });

    let prepare_res = run_preparation_command(&options.shell, &prepare_cmd, options.show_output)?;

    // Initial timing run
    let (res, success) = time_shell_command(
        &options.shell,
        cmd,
        options.show_output,
        options.failure_action,
        Some(shell_spawning_time),
    )?;

    // Determine number of benchmark runs
    let runs_in_min_time = (options.min_time_sec
        / (res.time_real + prepare_res.time_real + shell_spawning_time.time_real))