mirror of
https://github.com/sharkdp/hyperfine.git
synced 2026-10-30 16:40:18 +00:00
Fix a few clippy warnings
This commit is contained in:
1 parent
0a77b43d17
commit
35a513917d
3 files changed
+26
-29
No files matched your search
+13
-13
@@ -53,7 +53,7 @@ pub fn time_shell_command(
|
||||
|
||||
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
|
||||
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
|
||||
pub fn mean_shell_spawning_time() -> io::Result<Second> {
|
||||
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![];
|
||||
for _ in 0..COUNT {
|
||||
@@ -94,9 +94,9 @@ pub fn mean_shell_spawning_time() -> io::Result<Second> {
|
||||
times.push(r.execution_time);
|
||||
}
|
||||
}
|
||||
bar.inc(1);
|
||||
progress_bar.inc(1);
|
||||
}
|
||||
bar.finish_and_clear();
|
||||
progress_bar.finish_and_clear();
|
||||
|
||||
Ok(mean(×))
|
||||
}
|
||||
@@ -121,17 +121,17 @@ pub fn run_benchmark(
|
||||
|
||||
// Warmup phase
|
||||
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 {
|
||||
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)
|
||||
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
|
||||
let run_preparation_command = || {
|
||||
@@ -161,7 +161,7 @@ pub fn run_benchmark(
|
||||
all_succeeded = all_succeeded && res.success;
|
||||
|
||||
// Re-configure the progress bar
|
||||
bar.set_length(count_remaining);
|
||||
progress_bar.set_length(count_remaining);
|
||||
|
||||
// Gather statistics
|
||||
for _ in 0..count_remaining {
|
||||
@@ -171,16 +171,16 @@ pub fn run_benchmark(
|
||||
let mean = format_duration(mean(&execution_times), None);
|
||||
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))?;
|
||||
|
||||
execution_times.push(res.execution_time);
|
||||
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
|
||||
let t_mean = mean(&execution_times);
|
||||
@@ -224,7 +224,7 @@ pub fn run_benchmark(
|
||||
warnings.push(Warnings::NonZeroExitCode);
|
||||
}
|
||||
|
||||
if warnings.len() > 0 {
|
||||
if !warnings.is_empty() {
|
||||
eprintln!(" ");
|
||||
for warning in &warnings {
|
||||
eprintln!(" {}: {}", Yellow.paint("Warning"), warning);
|
||||
|
||||
+10
-12
@@ -54,12 +54,12 @@ pub fn get_progress_bar(length: u64, msg: &str) -> ProgressBar {
|
||||
.tick_chars("⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏")
|
||||
.template(" {spinner} {msg:<30} {wide_bar} ETA {eta_precise}");
|
||||
|
||||
let bar = ProgressBar::new(length);
|
||||
bar.set_style(progressbar_style.clone());
|
||||
bar.enable_steady_tick(80);
|
||||
bar.set_message(msg);
|
||||
let progress_bar = ProgressBar::new(length);
|
||||
progress_bar.set_style(progressbar_style.clone());
|
||||
progress_bar.enable_steady_tick(80);
|
||||
progress_bar.set_message(msg);
|
||||
|
||||
bar
|
||||
progress_bar
|
||||
}
|
||||
|
||||
/// Possible benchmark warnings
|
||||
@@ -70,31 +70,29 @@ pub enum Warnings {
|
||||
|
||||
impl fmt::Display for Warnings {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match self {
|
||||
&Warnings::FastExecutionTime => write!(
|
||||
match *self {
|
||||
Warnings::FastExecutionTime => write!(
|
||||
f,
|
||||
"Command took less than {:.0} ms to complete. Results might be inaccurate.",
|
||||
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
|
||||
pub fn max(vals: &[f64]) -> f64 {
|
||||
vals.iter()
|
||||
*vals.iter()
|
||||
.max_by(|a, b| a.partial_cmp(b).unwrap())
|
||||
.unwrap()
|
||||
.clone()
|
||||
}
|
||||
|
||||
/// A min function for f64's without NaNs
|
||||
pub fn min(vals: &[f64]) -> f64 {
|
||||
vals.iter()
|
||||
*vals.iter()
|
||||
.min_by(|a, b| a.partial_cmp(b).unwrap())
|
||||
.unwrap()
|
||||
.clone()
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
+3
-4
@@ -28,7 +28,7 @@ fn run(commands: &Vec<&str>, options: &HyperfineOptions) -> io::Result<()> {
|
||||
|
||||
// Run the benchmarks
|
||||
for (num, cmd) in commands.iter().enumerate() {
|
||||
run_benchmark(num, &cmd, shell_spawning_time, &options)?;
|
||||
run_benchmark(num, cmd, shell_spawning_time, options)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
@@ -116,8 +116,7 @@ fn main() {
|
||||
let commands = matches.values_of("command").unwrap().collect();
|
||||
let res = run(&commands, &options);
|
||||
|
||||
match res {
|
||||
Err(e) => error(e.description()),
|
||||
Ok(_) => {}
|
||||
if let Err(e) = res {
|
||||
error(e.description());
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user