Fix a few clippy warnings

This commit is contained in:
sharkdp committed 2018-01-18 20:19:03 +01:00
1 parent 0a77b43d17
commit 35a513917d
3 files changed
+26 -29

No files matched your search

+13 -13
View File
@@ -53,7 +53,7 @@ pub fn time_shell_command(
let duration = start.elapsed(); let duration = start.elapsed();
let execution_time = duration.as_secs() as f64 + duration.subsec_nanos() as f64 * 1e-9; let execution_time = duration.as_secs() as f64 + (duration.subsec_nanos() as f64) * 1e-9;
// Correct for shell spawning time // Correct for shell spawning time
let execution_time_corrected = if let Some(spawning_time) = shell_spawning_time { let execution_time_corrected = if let Some(spawning_time) = shell_spawning_time {
@@ -75,7 +75,7 @@ pub fn time_shell_command(
/// Measure the average shell spawning time /// Measure the average shell spawning time
pub fn mean_shell_spawning_time() -> io::Result<Second> { pub fn mean_shell_spawning_time() -> io::Result<Second> {
const COUNT: u64 = 200; const COUNT: u64 = 200;
let bar = get_progress_bar(COUNT, "Measuring shell spawning time"); let progress_bar = get_progress_bar(COUNT, "Measuring shell spawning time");
let mut times: Vec<Second> = vec![]; let mut times: Vec<Second> = vec![];
for _ in 0..COUNT { for _ in 0..COUNT {
@@ -94,9 +94,9 @@ pub fn mean_shell_spawning_time() -> io::Result<Second> {
times.push(r.execution_time); times.push(r.execution_time);
} }
} }
bar.inc(1); progress_bar.inc(1);
} }
bar.finish_and_clear(); progress_bar.finish_and_clear();
Ok(mean(&times)) Ok(mean(&times))
} }
@@ -121,17 +121,17 @@ pub fn run_benchmark(
// Warmup phase // Warmup phase
if options.warmup_count > 0 { if options.warmup_count > 0 {
let bar = get_progress_bar(options.warmup_count, "Performing warmup runs"); let progress_bar = get_progress_bar(options.warmup_count, "Performing warmup runs");
for _ in 0..options.warmup_count { for _ in 0..options.warmup_count {
let _ = time_shell_command(cmd, options.failure_action, None)?; let _ = time_shell_command(cmd, options.failure_action, None)?;
bar.inc(1); progress_bar.inc(1);
} }
bar.finish_and_clear(); progress_bar.finish_and_clear();
} }
// Set up progress bar (and spinner for initial measurement) // Set up progress bar (and spinner for initial measurement)
let bar = get_progress_bar(options.min_runs, "Initial time measurement"); let progress_bar = get_progress_bar(options.min_runs, "Initial time measurement");
// Run init / cleanup command // Run init / cleanup command
let run_preparation_command = || { let run_preparation_command = || {
@@ -161,7 +161,7 @@ pub fn run_benchmark(
all_succeeded = all_succeeded && res.success; all_succeeded = all_succeeded && res.success;
// Re-configure the progress bar // Re-configure the progress bar
bar.set_length(count_remaining); progress_bar.set_length(count_remaining);
// Gather statistics // Gather statistics
for _ in 0..count_remaining { for _ in 0..count_remaining {
@@ -171,16 +171,16 @@ pub fn run_benchmark(
let mean = format_duration(mean(&execution_times), None); let mean = format_duration(mean(&execution_times), None);
format!("Current estimate: {}", Green.paint(mean)) format!("Current estimate: {}", Green.paint(mean))
}; };
bar.set_message(&msg); progress_bar.set_message(&msg);
let res = time_shell_command(cmd, options.failure_action, Some(shell_spawning_time))?; let res = time_shell_command(cmd, options.failure_action, Some(shell_spawning_time))?;
execution_times.push(res.execution_time); execution_times.push(res.execution_time);
all_succeeded = all_succeeded && res.success; all_succeeded = all_succeeded && res.success;
bar.inc(1); progress_bar.inc(1);
} }
bar.finish_and_clear(); progress_bar.finish_and_clear();
// Compute statistical quantities // Compute statistical quantities
let t_mean = mean(&execution_times); let t_mean = mean(&execution_times);
@@ -224,7 +224,7 @@ pub fn run_benchmark(
warnings.push(Warnings::NonZeroExitCode); warnings.push(Warnings::NonZeroExitCode);
} }
if warnings.len() > 0 { if !warnings.is_empty() {
eprintln!(" "); eprintln!(" ");
for warning in &warnings { for warning in &warnings {
eprintln!(" {}: {}", Yellow.paint("Warning"), warning); eprintln!(" {}: {}", Yellow.paint("Warning"), warning);
+10 -12
View File
@@ -54,12 +54,12 @@ pub fn get_progress_bar(length: u64, msg: &str) -> ProgressBar {
.tick_chars("⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏") .tick_chars("⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏")
.template(" {spinner} {msg:<30} {wide_bar} ETA {eta_precise}"); .template(" {spinner} {msg:<30} {wide_bar} ETA {eta_precise}");
let bar = ProgressBar::new(length); let progress_bar = ProgressBar::new(length);
bar.set_style(progressbar_style.clone()); progress_bar.set_style(progressbar_style.clone());
bar.enable_steady_tick(80); progress_bar.enable_steady_tick(80);
bar.set_message(msg); progress_bar.set_message(msg);
bar progress_bar
} }
/// Possible benchmark warnings /// Possible benchmark warnings
@@ -70,31 +70,29 @@ pub enum Warnings {
impl fmt::Display for Warnings { impl fmt::Display for Warnings {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self { match *self {
&Warnings::FastExecutionTime => write!( Warnings::FastExecutionTime => write!(
f, f,
"Command took less than {:.0} ms to complete. Results might be inaccurate.", "Command took less than {:.0} ms to complete. Results might be inaccurate.",
MIN_EXECUTION_TIME * 1e3 MIN_EXECUTION_TIME * 1e3
), ),
&Warnings::NonZeroExitCode => write!(f, "Ignoring non-zero exit code."), Warnings::NonZeroExitCode => write!(f, "Ignoring non-zero exit code."),
} }
} }
} }
/// A max function for f64's without NaNs /// A max function for f64's without NaNs
pub fn max(vals: &[f64]) -> f64 { pub fn max(vals: &[f64]) -> f64 {
vals.iter() *vals.iter()
.max_by(|a, b| a.partial_cmp(b).unwrap()) .max_by(|a, b| a.partial_cmp(b).unwrap())
.unwrap() .unwrap()
.clone()
} }
/// A min function for f64's without NaNs /// A min function for f64's without NaNs
pub fn min(vals: &[f64]) -> f64 { pub fn min(vals: &[f64]) -> f64 {
vals.iter() *vals.iter()
.min_by(|a, b| a.partial_cmp(b).unwrap()) .min_by(|a, b| a.partial_cmp(b).unwrap())
.unwrap() .unwrap()
.clone()
} }
#[test] #[test]
+3 -4
View File
@@ -28,7 +28,7 @@ fn run(commands: &Vec<&str>, options: &HyperfineOptions) -> io::Result<()> {
// Run the benchmarks // Run the benchmarks
for (num, cmd) in commands.iter().enumerate() { for (num, cmd) in commands.iter().enumerate() {
run_benchmark(num, &cmd, shell_spawning_time, &options)?; run_benchmark(num, cmd, shell_spawning_time, options)?;
} }
Ok(()) Ok(())
@@ -116,8 +116,7 @@ fn main() {
let commands = matches.values_of("command").unwrap().collect(); let commands = matches.values_of("command").unwrap().collect();
let res = run(&commands, &options); let res = run(&commands, &options);
match res { if let Err(e) = res {
Err(e) => error(e.description()), error(e.description());
Ok(_) => {}
} }
} }