mirror of
https://github.com/sharkdp/hyperfine.git
synced 2026-11-02 09:01:25 +00:00
Rename parameter to '--parameter-scan'
This commit is contained in:
1 parent
e862cf8567
commit
07f142528e
2 files changed
+21
-21
No files matched your search
+10
-10
@@ -3,35 +3,35 @@ use std::error::Error;
|
|||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum ParameterRangeError {
|
pub enum ParameterScanError {
|
||||||
ParseIntError(num::ParseIntError),
|
ParseIntError(num::ParseIntError),
|
||||||
EmptyRange,
|
EmptyRange,
|
||||||
TooLarge,
|
TooLarge,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ParameterRangeError {
|
impl ParameterScanError {
|
||||||
fn __description(&self) -> &str {
|
fn __description(&self) -> &str {
|
||||||
match *self {
|
match *self {
|
||||||
ParameterRangeError::ParseIntError(ref e) => e.description(),
|
ParameterScanError::ParseIntError(ref e) => e.description(),
|
||||||
ParameterRangeError::EmptyRange => "Empty parameter range",
|
ParameterScanError::EmptyRange => "Empty parameter range",
|
||||||
ParameterRangeError::TooLarge => "Parameter range is too large",
|
ParameterScanError::TooLarge => "Parameter range is too large",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<num::ParseIntError> for ParameterRangeError {
|
impl From<num::ParseIntError> for ParameterScanError {
|
||||||
fn from(e: num::ParseIntError) -> ParameterRangeError {
|
fn from(e: num::ParseIntError) -> ParameterScanError {
|
||||||
ParameterRangeError::ParseIntError(e)
|
ParameterScanError::ParseIntError(e)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Display for ParameterRangeError {
|
impl fmt::Display for ParameterScanError {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
write!(f, "{}", self.__description())
|
write!(f, "{}", self.__description())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Error for ParameterRangeError {
|
impl Error for ParameterScanError {
|
||||||
fn description(&self) -> &str {
|
fn description(&self) -> &str {
|
||||||
self.__description()
|
self.__description()
|
||||||
}
|
}
|
||||||
|
|||||||
+11
-11
@@ -43,7 +43,7 @@ use hyperfine::types::{BenchmarkResult, CmdFailureAction, Command, HyperfineOpti
|
|||||||
OutputStyleOption};
|
OutputStyleOption};
|
||||||
use hyperfine::benchmark::{mean_shell_spawning_time, run_benchmark};
|
use hyperfine::benchmark::{mean_shell_spawning_time, run_benchmark};
|
||||||
use hyperfine::export::{ExportManager, ExportType};
|
use hyperfine::export::{ExportManager, ExportType};
|
||||||
use hyperfine::error::ParameterRangeError;
|
use hyperfine::error::ParameterScanError;
|
||||||
|
|
||||||
/// Print error message to stderr and terminate
|
/// Print error message to stderr and terminate
|
||||||
pub fn error(message: &str) -> ! {
|
pub fn error(message: &str) -> ! {
|
||||||
@@ -65,21 +65,21 @@ fn run(commands: &Vec<Command>, options: &HyperfineOptions) -> io::Result<Vec<Be
|
|||||||
Ok(timing_results)
|
Ok(timing_results)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A function to read the `--parameter-range` arguments
|
/// A function to read the `--parameter-scan` arguments
|
||||||
fn parse_parameter_range_args<'a>(
|
fn parse_parameter_scan_args<'a>(
|
||||||
mut vals: clap::Values<'a>,
|
mut vals: clap::Values<'a>,
|
||||||
) -> Result<(&'a str, Range<i32>), ParameterRangeError> {
|
) -> Result<(&'a str, Range<i32>), ParameterScanError> {
|
||||||
let param_name = vals.next().unwrap();
|
let param_name = vals.next().unwrap();
|
||||||
let param_min: i32 = vals.next().unwrap().parse()?;
|
let param_min: i32 = vals.next().unwrap().parse()?;
|
||||||
let param_max: i32 = vals.next().unwrap().parse()?;
|
let param_max: i32 = vals.next().unwrap().parse()?;
|
||||||
|
|
||||||
const MAX_PARAMETERS: i32 = 100000;
|
const MAX_PARAMETERS: i32 = 100000;
|
||||||
if param_max - param_min > MAX_PARAMETERS {
|
if param_max - param_min > MAX_PARAMETERS {
|
||||||
return Err(ParameterRangeError::TooLarge);
|
return Err(ParameterScanError::TooLarge);
|
||||||
}
|
}
|
||||||
|
|
||||||
if param_max < param_min {
|
if param_max < param_min {
|
||||||
return Err(ParameterRangeError::EmptyRange);
|
return Err(ParameterScanError::EmptyRange);
|
||||||
}
|
}
|
||||||
|
|
||||||
return Ok((param_name, param_min..(param_max + 1)));
|
return Ok((param_name, param_min..(param_max + 1)));
|
||||||
@@ -163,9 +163,9 @@ fn main() {
|
|||||||
.help("Ignore non-zero exit codes."),
|
.help("Ignore non-zero exit codes."),
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::with_name("parameter-range")
|
Arg::with_name("parameter-scan")
|
||||||
.long("parameter-range")
|
.long("parameter-scan")
|
||||||
.short("r")
|
.short("P")
|
||||||
.help(
|
.help(
|
||||||
"Perform benchmark runs for each value in the range MIN..MAX. Replaces the \
|
"Perform benchmark runs for each value in the range MIN..MAX. Replaces the \
|
||||||
string '{VAR}' in each command by the current parameter value.",
|
string '{VAR}' in each command by the current parameter value.",
|
||||||
@@ -249,8 +249,8 @@ fn main() {
|
|||||||
|
|
||||||
let command_strings = matches.values_of("command").unwrap();
|
let command_strings = matches.values_of("command").unwrap();
|
||||||
|
|
||||||
let commands = if let Some(args) = matches.values_of("parameter-range") {
|
let commands = if let Some(args) = matches.values_of("parameter-scan") {
|
||||||
match parse_parameter_range_args(args) {
|
match parse_parameter_scan_args(args) {
|
||||||
Ok((param_name, param_range)) => {
|
Ok((param_name, param_range)) => {
|
||||||
let mut commands = vec![];
|
let mut commands = vec![];
|
||||||
let command_strings = command_strings.collect::<Vec<&str>>();
|
let command_strings = command_strings.collect::<Vec<&str>>();
|
||||||
|
|||||||
Reference in new issue
Block a user