Fix a few clippy warnings
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by sharkdp · committed by sharkdp · parent 0a77b43 · Browse files · 3 files·+26 added−29 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
3 files+26 added−29 removed
- other:+26 added−29 removed
Provenance
- Commit
35a5139- Tree
a923643- Author
sharkdp <davidpeter@web.de>- Committer
sharkdp <davidpeter@web.de>- Parent
0a77b43
3 files changed+26 added−29 removed
modified:src/hyperfine/benchmark.rs+13 added-13 removed
51 unmodified lines52 }53 54 let duration = start.elapsed();55 56- let execution_time = duration.as_secs() as f64 + duration.subsec_nanos() as f64 * 1e-9;56+ let execution_time = duration.as_secs() as f64 + (duration.subsec_nanos() as f64) * 1e-9;57 58 // Correct for shell spawning time59 let execution_time_corrected = if let Some(spawning_time) = shell_spawning_time {60 if execution_time < spawning_time {13 unmodified lines74 75 /// Measure the average shell spawning time76 pub fn mean_shell_spawning_time() -> io::Result<Second> {77 const COUNT: u64 = 200;78- let bar = get_progress_bar(COUNT, "Measuring shell spawning time");78+ let progress_bar = get_progress_bar(COUNT, "Measuring shell spawning time");79 80 let mut times: Vec<Second> = vec![];81 for _ in 0..COUNT {82 // Just run the shell without any command10 unmodified lines93 Ok(r) => {94 times.push(r.execution_time);95 }96 }97- bar.inc(1);97+ progress_bar.inc(1);98 }99- bar.finish_and_clear();99+ progress_bar.finish_and_clear();100 101 Ok(mean(×))102 }103 16 unmodified lines120 let mut all_succeeded = true;121 122 // Warmup phase123 if options.warmup_count > 0 {124- let bar = get_progress_bar(options.warmup_count, "Performing warmup runs");124+ let progress_bar = get_progress_bar(options.warmup_count, "Performing warmup runs");125 126 for _ in 0..options.warmup_count {127 let _ = time_shell_command(cmd, options.failure_action, None)?;128- bar.inc(1);128+ progress_bar.inc(1);129 }130- bar.finish_and_clear();130+ progress_bar.finish_and_clear();131 }132 133 // Set up progress bar (and spinner for initial measurement)134- let bar = get_progress_bar(options.min_runs, "Initial time measurement");134+ let progress_bar = get_progress_bar(options.min_runs, "Initial time measurement");135 136 // Run init / cleanup command137 let run_preparation_command = || {138 if let Some(ref preparation_command) = options.preparation_command {21 unmodified lines160 execution_times.push(res.execution_time);161 all_succeeded = all_succeeded && res.success;162 163 // Re-configure the progress bar164- bar.set_length(count_remaining);164+ progress_bar.set_length(count_remaining);165 166 // Gather statistics167 for _ in 0..count_remaining {168 run_preparation_command();1 unmodified line170 let msg = {171 let mean = format_duration(mean(&execution_times), None);172 format!("Current estimate: {}", Green.paint(mean))173 };174- bar.set_message(&msg);174+ progress_bar.set_message(&msg);175 176 let res = time_shell_command(cmd, options.failure_action, Some(shell_spawning_time))?;177 178 execution_times.push(res.execution_time);179 all_succeeded = all_succeeded && res.success;180 181- bar.inc(1);181+ progress_bar.inc(1);182 }183- bar.finish_and_clear();183+ progress_bar.finish_and_clear();184 185 // Compute statistical quantities186 let t_mean = mean(&execution_times);187 let t_stddev = standard_deviation(&execution_times, Some(t_mean));35 unmodified lines223 if !all_succeeded {224 warnings.push(Warnings::NonZeroExitCode);225 }226 227- if warnings.len() > 0 {227+ if !warnings.is_empty() {228 eprintln!(" ");229 for warning in &warnings {230 eprintln!(" {}: {}", Yellow.paint("Warning"), warning);231 }6 unmodified linesmodified:src/hyperfine/internal.rs+10 added-12 removed
52 unmodified lines53 let progressbar_style = ProgressStyle::default_spinner()54 .tick_chars("⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏")55 .template(" {spinner} {msg:<30} {wide_bar} ETA {eta_precise}");56 57- let bar = ProgressBar::new(length);58- bar.set_style(progressbar_style.clone());59- bar.enable_steady_tick(80);60- bar.set_message(msg);57+ let progress_bar = ProgressBar::new(length);58+ progress_bar.set_style(progressbar_style.clone());59+ progress_bar.enable_steady_tick(80);60+ progress_bar.set_message(msg);61 62- bar62+ progress_bar63 }64 65 /// Possible benchmark warnings66 pub enum Warnings {2 unmodified lines69 }70 71 impl fmt::Display for Warnings {72 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {73- match self {74- &Warnings::FastExecutionTime => write!(73+ match *self {74+ Warnings::FastExecutionTime => write!(75 f,76 "Command took less than {:.0} ms to complete. Results might be inaccurate.",77 MIN_EXECUTION_TIME * 1e378 ),79- &Warnings::NonZeroExitCode => write!(f, "Ignoring non-zero exit code."),79+ Warnings::NonZeroExitCode => write!(f, "Ignoring non-zero exit code."),80 }81 }82 }83 84 /// A max function for f64's without NaNs85 pub fn max(vals: &[f64]) -> f64 {86- vals.iter()86+ *vals.iter()87 .max_by(|a, b| a.partial_cmp(b).unwrap())88 .unwrap()89- .clone()89 }90 91 /// A min function for f64's without NaNs92 pub fn min(vals: &[f64]) -> f64 {94- vals.iter()93+ *vals.iter()94 .min_by(|a, b| a.partial_cmp(b).unwrap())95 .unwrap()97- .clone()96 }97 98 #[test]99 fn test_max() {6 unmodified linesmodified:src/main.rs+3 added-4 removed
26 unmodified lines27 let shell_spawning_time = mean_shell_spawning_time()?;28 29 // Run the benchmarks30 for (num, cmd) in commands.iter().enumerate() {31- run_benchmark(num, &cmd, shell_spawning_time, &options)?;31+ run_benchmark(num, cmd, shell_spawning_time, options)?;32 }33 34 Ok(())35 }79 unmodified lines115 116 let commands = matches.values_of("command").unwrap().collect();117 let res = run(&commands, &options);118 119- match res {120- Err(e) => error(e.description()),121- Ok(_) => {}119+ if let Err(e) = res {120+ error(e.description());121 }122 }