From 0466a1d7cf99a68943478888fc547dcc4d36992c Mon Sep 17 00:00:00 2001 From: Diogo Sousa Date: Sun, 9 Sep 2018 21:52:58 +0100 Subject: [PATCH] Addressed review comments. --- src/hyperfine/app.rs | 1 + src/hyperfine/benchmark.rs | 11 +++++++---- src/hyperfine/types.rs | 4 ++-- src/main.rs | 4 ++-- 4 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/hyperfine/app.rs b/src/hyperfine/app.rs index f7aa44a..2cc9b35 100644 --- a/src/hyperfine/app.rs +++ b/src/hyperfine/app.rs @@ -65,6 +65,7 @@ fn build_app() -> App<'static, 'static> { .arg( Arg::with_name("runs") .long("runs") + .conflicts_with_all(&["max-runs", "min-runs"]) .short("r") .takes_value(true) .value_name("NUM") diff --git a/src/hyperfine/benchmark.rs b/src/hyperfine/benchmark.rs index 332b7ad..72e2b78 100644 --- a/src/hyperfine/benchmark.rs +++ b/src/hyperfine/benchmark.rs @@ -216,10 +216,13 @@ pub fn run_benchmark( / (res.time_real + prepare_res.time_real + shell_spawning_time.time_real)) as u64; - let count = cmp::min( - cmp::max(runs_in_min_time, options.runs.min), - options.runs.max - ); + 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) + }; let count_remaining = count - 1; diff --git a/src/hyperfine/types.rs b/src/hyperfine/types.rs index 690507c..c19cb06 100644 --- a/src/hyperfine/types.rs +++ b/src/hyperfine/types.rs @@ -79,14 +79,14 @@ pub struct Runs { pub min: u64, /// Maximum number of benchmark runs - pub max: u64, + pub max: Option, } impl Default for Runs { fn default() -> Runs { Runs { min: 10, - max: ::std::u64::MAX, + max: None, } } } diff --git a/src/main.rs b/src/main.rs index 189fe6e..371de0f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -148,14 +148,14 @@ fn build_hyperfine_options(matches: &ArgMatches) -> Result { // Since the minimum was not explicit we lower it if max is below the default min. options.runs.min = cmp::min(options.runs.min, max); - options.runs.max = max; + options.runs.max = Some(max); } (Some(min), Some(max)) if min > max => { return Err(OptionsError::EmptyRunsRange); } (Some(min), Some(max)) => { options.runs.min = min; - options.runs.max = max; + options.runs.max = Some(max); } (None, None) => {} };