Skip to content
Myr

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

3 files+26 added−29 removed

modified:src/hyperfine/benchmark.rs+13 added-13 removed
51 unmodified lines
52 }5354 let duration = start.elapsed();5556 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;5758 // 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 lines
7475/// Measure the average shell spawning time76pub 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");7980 let mut times: Vec<Second> = vec![];81 for _ in 0..COUNT {82 // Just run the shell without any command
10 unmodified lines
93 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();100101 Ok(mean(&times))102}103
16 unmodified lines
120 let mut all_succeeded = true;121122 // 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");125126 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 }132133 // 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");135136 // Run init / cleanup command137 let run_preparation_command = || {138 if let Some(ref preparation_command) = options.preparation_command {
21 unmodified lines
160 execution_times.push(res.execution_time);161 all_succeeded = all_succeeded && res.success;162163 // Re-configure the progress bar164 bar.set_length(count_remaining);164 progress_bar.set_length(count_remaining);165166 // Gather statistics167 for _ in 0..count_remaining {168 run_preparation_command();
1 unmodified line
170 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);175176 let res = time_shell_command(cmd, options.failure_action, Some(shell_spawning_time))?;177178 execution_times.push(res.execution_time);179 all_succeeded = all_succeeded && res.success;180181 bar.inc(1);181 progress_bar.inc(1);182 }183 bar.finish_and_clear();183 progress_bar.finish_and_clear();184185 // Compute statistical quantities186 let t_mean = mean(&execution_times);187 let t_stddev = standard_deviation(&execution_times, Some(t_mean));
35 unmodified lines
223 if !all_succeeded {224 warnings.push(Warnings::NonZeroExitCode);225 }226227 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 lines
modified:src/hyperfine/internal.rs+10 added-12 removed
52 unmodified lines
53 let progressbar_style = ProgressStyle::default_spinner()54 .tick_chars("⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏")55 .template(" {spinner} {msg:<30} {wide_bar} ETA {eta_precise}");5657 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);6162 bar62 progress_bar63}6465/// Possible benchmark warnings66pub enum Warnings {
2 unmodified lines
69}7071impl 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}8384/// A max function for f64's without NaNs85pub 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}9091/// A min function for f64's without NaNs92pub 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}9798#[test]99fn test_max() {
6 unmodified lines
modified:src/main.rs+3 added-4 removed
26 unmodified lines
27 let shell_spawning_time = mean_shell_spawning_time()?;2829 // 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 }3334 Ok(())35}
79 unmodified lines
115116 let commands = matches.values_of("command").unwrap().collect();117 let res = run(&commands, &options);118119 match res {120 Err(e) => error(e.description()),121 Ok(_) => {}119 if let Err(e) = res {120 error(e.description());121 }122}