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

Code before:
        if self.step == T::from(0) {
            return (usize::MAX, None);
        }

        let steps = (self.end - self.state + T::from(1)) / self.step;
        steps
            .into()
            .try_into()
            .map_or((usize::MAX, None), |u| (u, Some(u)))
    }
}

fn build_parameterized_commands<'a, T: Numeric>(
    param_min: T,
    param_max: T,
    step: T,
    command_names: Vec<&'a str>,
    command_strings: Vec<&'a str>,
    param_name: &'a str,
) -> Result<Vec<Command<'a>>, ParameterScanError> {
    let param_range = RangeStep::new(param_min, param_max, step);
    param_range.validate()?;
    let param_count = param_range.size_hint().1.unwrap();
    let command_name_count = command_names.len();

    // `--command-name` should appear exactly once or same count with parameters.
    if command_name_count > 1 && command_name_count != param_count {
        return Err(ParameterScanError::DifferentCommandNameCountWithParameters(
            command_name_count,
            param_count,
        ));
    }

    let mut i = 0;
    let mut commands = vec![];
    for value in param_range {
        for cmd in &command_strings {
            let name = command_names
                .get(i)
                .or_else(|| command_names.get(0))
                .map(|s| *s);
            commands.push(Command::new_parametrized(
                name,
                cmd,
                vec![(param_name, ParameterValue::Numeric(value.into()))],
            ));
            i += 1;
        }
    }
    Ok(commands)
}

Review comment (suggestion):
Shouldn't this be something like:
```
    // `--command-name` should appear exactly once or exactly B times,
    // where B is the total number of benchmarks.
```

Code after:

fn range_step_size_hint<T: Numeric>(start: T, end: T, step: T) -> (usize, Option<usize>) {
    if step == T::from(0) {
        return (usize::MAX, None);
    }

    let steps = (end - start + T::from(1)) / step;
    steps
        .into()
        .try_into()
        .map_or((usize::MAX, None), |u| (u, Some(u)))
}

fn build_parameterized_commands<'a, T: Numeric>(
    param_min: T,
    param_max: T,
    step: T,
    command_names: Vec<&'a str>,
    command_strings: Vec<&'a str>,
    param_name: &'a str,
) -> Result<Vec<Command<'a>>, ParameterScanError> {
    let param_range = RangeStep::new(param_min, param_max, step)?;
    let param_count = param_range.size_hint().1.unwrap();
    let command_name_count = command_names.len();

    // `--command-name` should appear exactly once or exactly B times,
    // where B is the total number of benchmarks.
    if command_name_count > 1 && command_name_count != param_count {
        return Err(ParameterScanError::UnexpectedCommandNameCount(
            command_name_count,
            param_count,
        ));
    }

    let mut i = 0;
    let mut commands = vec![];
    for value in param_range {
        for cmd in &command_strings {
            let name = command_names
                .get(i)
                .or_else(|| command_names.get(0))
                .map(|s| *s);
            commands.push(Command::new_parametrized(
                name,
                cmd,
                vec![(param_name, ParameterValue::Numeric(value.into()))],
            ));
            i += 1;
        }
    }
    Ok(commands)