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

Code before:
                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);

        options
            .runs
            .max
            .as_ref()
            .map(|max| cmp::min(min, *max))
            .unwrap_or(min)
    };


Review comment (suggestion):
how about first storing `&values[0]` or `&values[num]` in a local variable. Then, you only need to call `new_command_from…` once. If this works, we could remove that function again and inline it here.

Code after:
                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))
        as u64;

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

        options
            .runs
            .max
            .as_ref()