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

Code before:

    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,
        ))
    }

    // Run init command
    let prepare_cmd = options
        .preparation_command
        .as_ref()
        .map(|preparation_command| 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)?;


Review comment (suggestion):
We should avoid `.clone()`ing. You can probably use `if let Some(ref pbar) = …`

Code after:
            "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(
            options.runs.min,
            "Initial time measurement",
            options.output_style,
        ))
    } else {
        None
    };

    // Run init command
    let prepare_cmd = options