Skip to content
Myr

Add --warmup option, closes #1

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by sharkdp · committed by sharkdp · parent 197f9fb · Browse files · 1 file+44 added−10 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+44 added−10 removed

  • other:+44 added−10 removed

1 file+44 added−10 removed

modified:src/main.rs+44 added-10 removed
43 unmodified lines
4445 CmdResult::new(execution_time_sec, status.success())46}4748/// Return a pre-configured progress bar49fn get_progress_bar(length: u64, msg: &str) -> ProgressBar {50 let progressbar_style = ProgressStyle::default_spinner()51 .tick_chars("⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏")52 .template(" {spinner} {msg:<28} {wide_bar} ETA {eta_precise}");5354 let bar = ProgressBar::new(length);55 bar.set_style(progressbar_style.clone());56 bar.enable_steady_tick(80);57 bar.set_message(msg);5859 bar60}6162fn main() {63 let matches = App::new("hyperfine")64 .global_settings(&[AppSettings::ColoredHelp])65 .version("0.1")
4 unmodified lines
70 .help("Command to benchmark")71 .required(true)72 .multiple(true),73 )74 .arg(75 Arg::with_name("warmup")76 .long("warmup")77 .short("w")78 .takes_value(true)79 .value_name("NUM")80 .help("Perform NUM warmup runs before the actual benchmark"),81 )82 .get_matches();8384 let min_time_sec = 5.0;85 let min_runs = 10;8665 let progressbar_style = ProgressStyle::default_spinner()66 .tick_chars("⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏")67 .template(" {spinner} {msg:<30} {wide_bar} ETA {eta_precise}");6887 let commands = matches.values_of("command").unwrap();8889 for cmd in commands {90 println!("Command: {}", Cyan.paint(cmd));91 println!();9293 let mut results = vec![];9477 // Set up progress bar78 let bar = ProgressBar::new(min_runs);79 bar.set_style(progressbar_style.clone());80 bar.enable_steady_tick(80);81 bar.set_message("Initial time measurement");95 // Warmup phase96 if let Some(warmup_count) = matches97 .value_of("warmup")98 .and_then(|n| u64::from_str_radix(n, 10).ok())99 {100 let bar = get_progress_bar(warmup_count, "Performing warmup runs");101102 for _ in 1..warmup_count {103 bar.inc(1);104 let _ = time_shell_command(cmd);105 }106 bar.finish_and_clear();107 }108109 // Set up progress bar (and spinner for initial measurement)110 let bar = get_progress_bar(min_runs, "Initial time measurement");11183 // Initial run112 // Initial timing run113 let res = time_shell_command(cmd);114115 let runs_in_min_time = (min_time_sec / res.execution_time_sec) as u64;116
2 unmodified lines
119 } else {120 min_runs121 };122123 // Save the first result124 results.push(res);125126 // Re-configure the progress bar127 bar.set_length(count);128 bar.set_message("Collecting statistics");129130 // Gather statistics131 for _ in 1..count {132 bar.inc(1);133 let res = time_shell_command(cmd);134 results.push(res);135 }136 bar.finish_and_clear();137138 // Compute statistical quantities139 let t_sum: f64 = results.iter().map(|r| r.execution_time_sec).sum();140 let t_mean = t_sum / (results.len() as f64);141142 let t2_sum: f64 = results.iter().map(|r| r.execution_time_sec.powi(2)).sum();143 let t2_mean = t2_sum / (results.len() as f64);144145 let stddev = (t2_mean - t_mean.powi(2)).sqrt();146147 // Formatting and console output148 let time_fmt = format!("{:.3} s ± {:.3} s", t_mean, stddev);149150 println!(" Time: {}", Green.paint(time_fmt));151
10 unmodified lines