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

Code before:
    options: &HyperfineOptions,
) -> io::Result<BenchmarkResult> {
    if options.output_style != OutputStyleOption::None { 
        println!(
            "{}{}: {}",
            "Benchmark #".bold(),
            (num + 1).to_string().bold(),
            cmd
        );
    }

    let mut times_real: Vec<Second> = vec![];
    let mut times_user: Vec<Second> = vec![];
    let mut times_system: Vec<Second> = vec![];
    let mut all_succeeded = true;

    // Warmup phase
    if options.warmup_count > 0 {
        let mut progress_bar: Option<ProgressBar> = None;
        if options.output_style != OutputStyleOption::None { 
                progress_bar = Some(get_progress_bar(
                options.warmup_count,
                "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,
            )?;
            if let Some(pbar) = progress_bar.clone() { pbar.inc(1); }
        }
        if let Some(bar) = progress_bar { bar.finish_and_clear(); }
    }

    // Set up progress bar (and spinner for initial measurement)
    let mut progress_bar:Option<ProgressBar> = None;

    if options.output_style != OutputStyleOption::None { 
            progress_bar = Some(get_progress_bar(
            options.runs.min,
            "Initial time measurement",
            options.output_style,
        ))
    }


Review comment (suggestion):
We could avoid `mut` here by writing this as
```
let progress_bar = if … {
  …
} else {
  …
};
```

Code after:
/// Run the benchmark for a single shell command
pub fn run_benchmark(
    num: usize,
    cmd: &Command<'_>,
    shell_spawning_time: TimingResult,
    options: &HyperfineOptions,
) -> io::Result<BenchmarkResult> {
    if options.output_style != OutputStyleOption::Disabled {
        println!(
            "{}{}: {}",
            "Benchmark #".bold(),
            (num + 1).to_string().bold(),
            cmd
        );
    }

    let mut times_real: Vec<Second> = vec![];
    let mut times_user: Vec<Second> = vec![];
    let mut times_system: Vec<Second> = vec![];
    let mut all_succeeded = true;

    // Warmup phase
    if options.warmup_count > 0 {
        let progress_bar = if options.output_style != OutputStyleOption::Disabled {
            Some(get_progress_bar(
                options.warmup_count,
                "Performing warmup runs",
                options.output_style,
            ))
        } else {
            None
        };

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

    // Set up progress bar (and spinner for initial measurement)
    let progress_bar = if options.output_style != OutputStyleOption::Disabled {
        Some(get_progress_bar(