Format source code
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by sharkdp · committed by sharkdp · parent 3144c4b · Browse files · 4 files·+146 added−99 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
4 files+146 added−99 removed
- other:+146 added−99 removed
Provenance
- Commit
a4cf1ea- Tree
4ef26d7- Author
sharkdp <davidpeter@web.de>- Committer
sharkdp <davidpeter@web.de>- Parent
3144c4b
4 files changed+146 added−99 removed
modified:src/hyperfine/export/markdown.rs+111 added-89 removed
31 unmodified lines32 }33 }34 35 fn table_header(unit_short_name: String) -> String {36- format!("| Command | Mean [{unit}] | Min…Max [{unit}] |\n|:---|---:|---:|\n", unit=unit_short_name)36+ format!(37+ "| Command | Mean [{unit}] | Min…Max [{unit}] |\n|:---|---:|---:|\n",38+ unit = unit_short_name39+ )40 }41 42 fn start_table(unit: Unit) -> Vec<u8> {43 table_header(unit.short_name()).bytes().collect()7 unmodified lines51 52 dest.extend(53 format!(54 "| `{command}` | {mean} ± {stddev} | {min}…{max} |\n",52- command=entry.command.replace("|", "\\|"),53- mean=mean_str,54- stddev=stddev_str,55- min=min_str,56- max=max_str,57- ).as_bytes(),55+ command = entry.command.replace("|", "\\|"),56+ mean = mean_str,57+ stddev = stddev_str,58+ min = min_str,59+ max = max_str,60+ )61+ .as_bytes(),62 );63 }64 65 /// Ensure the markdown output includes the table header and the multiple8 unmodified lines74 75 let mut timing_results = vec![];76 77 timing_results.push(BenchmarkResult::new(74- String::from("sleep 0.1"),75- 0.1057, // mean76- 0.0016, // std dev77- 0.0009, // user_mean78- 0.0011, // system_mean79- 0.1023, // min80- 0.1080, // max81- vec![0.1, 0.1, 0.1], // times82- ));78+ String::from("sleep 0.1"),79+ 0.1057, // mean80+ 0.0016, // std dev81+ 0.0009, // user_mean82+ 0.0011, // system_mean83+ 0.1023, // min84+ 0.1080, // max85+ vec![0.1, 0.1, 0.1], // times86+ ));87 88 timing_results.push(BenchmarkResult::new(85- String::from("sleep 2"),86- 2.0050, // mean87- 0.0020, // std dev88- 0.0009, // user_mean89- 0.0012, // system_mean90- 2.0020, // min91- 2.0080, // max92- vec![2.0, 2.0, 2.0], // times93- ));89+ String::from("sleep 2"),90+ 2.0050, // mean91+ 0.0020, // std dev92+ 0.0009, // user_mean93+ 0.0012, // system_mean94+ 2.0020, // min95+ 2.0080, // max96+ vec![2.0, 2.0, 2.0], // times97+ ));98 99 let formatted = String::from_utf8(exporter.serialize(&timing_results, None).unwrap()).unwrap();100 101 let formatted_expected = format!(98-"{}\102+ "{}\103 | `sleep 0.1` | 105.7 ± 1.6 | 102.3…108.0 |104 | `sleep 2` | 2005.0 ± 2.0 | 2002.0…2008.0 |101-", table_header("ms".to_string()));105+",106+ table_header("ms".to_string())107+ );108 109 assert_eq!(formatted_expected, formatted);110 }111 5 unmodified lines117 118 let mut timing_results = vec![];119 120 timing_results.push(BenchmarkResult::new(115- String::from("sleep 2"),116- 2.0050, // mean117- 0.0020, // std dev118- 0.0009, // user_mean119- 0.0012, // system_mean120- 2.0020, // min121- 2.0080, // max122- vec![2.0, 2.0, 2.0], // times123- ));121+ String::from("sleep 2"),122+ 2.0050, // mean123+ 0.0020, // std dev124+ 0.0009, // user_mean125+ 0.0012, // system_mean126+ 2.0020, // min127+ 2.0080, // max128+ vec![2.0, 2.0, 2.0], // times129+ ));130 131 timing_results.push(BenchmarkResult::new(126- String::from("sleep 0.1"),127- 0.1057, // mean128- 0.0016, // std dev129- 0.0009, // user_mean130- 0.0011, // system_mean131- 0.1023, // min132- 0.1080, // max133- vec![0.1, 0.1, 0.1], // times134- ));132+ String::from("sleep 0.1"),133+ 0.1057, // mean134+ 0.0016, // std dev135+ 0.0009, // user_mean136+ 0.0011, // system_mean137+ 0.1023, // min138+ 0.1080, // max139+ vec![0.1, 0.1, 0.1], // times140+ ));141 142 let formatted = String::from_utf8(exporter.serialize(&timing_results, None).unwrap()).unwrap();143 144 let formatted_expected = format!(139-"{}\145+ "{}\146 | `sleep 2` | 2.005 ± 0.002 | 2.002…2.008 |147 | `sleep 0.1` | 0.106 ± 0.002 | 0.102…0.108 |142-", table_header("s".to_string()));148+",149+ table_header("s".to_string())150+ );151 152 assert_eq!(formatted_expected, formatted);153 }154 4 unmodified lines159 160 let mut timing_results = vec![];161 162 timing_results.push(BenchmarkResult::new(155- String::from("sleep 0.1"),156- 0.1057, // mean157- 0.0016, // std dev158- 0.0009, // user_mean159- 0.0011, // system_mean160- 0.1023, // min161- 0.1080, // max162- vec![0.1, 0.1, 0.1], // times163- ));163+ String::from("sleep 0.1"),164+ 0.1057, // mean165+ 0.0016, // std dev166+ 0.0009, // user_mean167+ 0.0011, // system_mean168+ 0.1023, // min169+ 0.1080, // max170+ vec![0.1, 0.1, 0.1], // times171+ ));172 173 timing_results.push(BenchmarkResult::new(166- String::from("sleep 2"),167- 2.0050, // mean168- 0.0020, // std dev169- 0.0009, // user_mean170- 0.0012, // system_mean171- 2.0020, // min172- 2.0080, // max173- vec![2.0, 2.0, 2.0], // times174- ));174+ String::from("sleep 2"),175+ 2.0050, // mean176+ 0.0020, // std dev177+ 0.0009, // user_mean178+ 0.0012, // system_mean179+ 2.0020, // min180+ 2.0080, // max181+ vec![2.0, 2.0, 2.0], // times182+ ));183 176- let formatted = String::from_utf8(exporter.serialize(&timing_results, Some(Unit::Second)).unwrap()).unwrap();184+ let formatted = String::from_utf8(185+ exporter186+ .serialize(&timing_results, Some(Unit::Second))187+ .unwrap(),188+ )189+ .unwrap();190 191 let formatted_expected = format!(179-"{}\192+ "{}\193 | `sleep 0.1` | 0.106 ± 0.002 | 0.102…0.108 |194 | `sleep 2` | 2.005 ± 0.002 | 2.002…2.008 |182-", table_header("s".to_string()));195+",196+ table_header("s".to_string())197+ );198 199 assert_eq!(formatted_expected, formatted);200 }201 5 unmodified lines207 208 let mut timing_results = vec![];209 210 timing_results.push(BenchmarkResult::new(196- String::from("sleep 2"),197- 2.0050, // mean198- 0.0020, // std dev199- 0.0009, // user_mean200- 0.0012, // system_mean201- 2.0020, // min202- 2.0080, // max203- vec![2.0, 2.0, 2.0], // times204- ));211+ String::from("sleep 2"),212+ 2.0050, // mean213+ 0.0020, // std dev214+ 0.0009, // user_mean215+ 0.0012, // system_mean216+ 2.0020, // min217+ 2.0080, // max218+ vec![2.0, 2.0, 2.0], // times219+ ));220 221 timing_results.push(BenchmarkResult::new(207- String::from("sleep 0.1"),208- 0.1057, // mean209- 0.0016, // std dev210- 0.0009, // user_mean211- 0.0011, // system_mean212- 0.1023, // min213- 0.1080, // max214- vec![0.1, 0.1, 0.1], // times215- ));222+ String::from("sleep 0.1"),223+ 0.1057, // mean224+ 0.0016, // std dev225+ 0.0009, // user_mean226+ 0.0011, // system_mean227+ 0.1023, // min228+ 0.1080, // max229+ vec![0.1, 0.1, 0.1], // times230+ ));231 217- let formatted = String::from_utf8(exporter.serialize(&timing_results, Some(Unit::MilliSecond)).unwrap()).unwrap();232+ let formatted = String::from_utf8(233+ exporter234+ .serialize(&timing_results, Some(Unit::MilliSecond))235+ .unwrap(),236+ )237+ .unwrap();238 239 let formatted_expected = format!(220-"{}\240+ "{}\241 | `sleep 2` | 2005.0 ± 2.0 | 2002.0…2008.0 |242 | `sleep 0.1` | 105.7 ± 1.6 | 102.3…108.0 |223-", table_header("ms".to_string()));243+",244+ table_header("ms".to_string())245+ );246 247 assert_eq!(formatted_expected, formatted);248 }modified:src/hyperfine/benchmark.rs+17 added-6 removed
9 unmodified lines10 use hyperfine::outlier_detection::{modified_zscores, OUTLIER_THRESHOLD};11 use hyperfine::shell::execute_and_time;12 use hyperfine::timer::wallclocktimer::WallClockTimer;13 use hyperfine::timer::{TimerStart, TimerStop};14-use hyperfine::types::{BenchmarkResult, Command, CmdFailureAction, HyperfineOptions, OutputStyleOption};14+use hyperfine::types::{15+ BenchmarkResult, CmdFailureAction, Command, HyperfineOptions, OutputStyleOption,16+};17 use hyperfine::units::Second;18 use hyperfine::warnings::Warnings;19 20 /// Results from timing a single shell command97 unmodified lines118 format!("{} -c \"\"", shell)119 };120 121 return Err(io::Error::new(120- io::ErrorKind::Other,121- format!("Could not measure shell execution time. \122- Make sure you can run '{}'.", shell_cmd),123- ))122+ io::ErrorKind::Other,123+ format!(124+ "Could not measure shell execution time. \125+ Make sure you can run '{}'.",126+ shell_cmd127+ ),128+ ));129 }130 Ok((r, _)) => {131 times_real.push(r.time_real);132 times_user.push(r.time_user);60 unmodified lines193 &options.output_style,194 );195 196 for _ in 0..options.warmup_count {192- let _ = time_shell_command(&options.shell, cmd, options.show_output, options.failure_action, None)?;197+ let _ = time_shell_command(198+ &options.shell,199+ cmd,200+ options.show_output,201+ options.failure_action,202+ None,203+ )?;204 progress_bar.inc(1);205 }206 progress_bar.finish_and_clear();207 }161 unmodified linesmodified:src/hyperfine/shell.rs+12 added-2 removed
17 unmodified lines18 }19 20 /// Execute the given command and return a timing summary21 #[cfg(windows)]22-pub fn execute_and_time(stdout: Stdio, stderr: Stdio, command: &str, shell: &str) -> io::Result<ExecuteResult> {22+pub fn execute_and_time(23+ stdout: Stdio,24+ stderr: Stdio,25+ command: &str,26+ shell: &str,27+) -> io::Result<ExecuteResult> {28 let mut child = run_shell_command(stdout, stderr, command, shell)?;29 let cpu_timer = get_cpu_timer(&child);30 let status = child.wait()?;31 6 unmodified lines38 }39 40 /// Execute the given command and return a timing summary41 #[cfg(not(windows))]37-pub fn execute_and_time(stdout: Stdio, stderr: Stdio, command: &str, shell: &str) -> io::Result<ExecuteResult> {42+pub fn execute_and_time(43+ stdout: Stdio,44+ stderr: Stdio,45+ command: &str,46+ shell: &str,47+) -> io::Result<ExecuteResult> {48 let cpu_timer = get_cpu_timer();49 50 let status = run_shell_command(stdout, stderr, command, shell)?;51 42 unmodified linesmodified:src/main.rs+6 added-2 removed
56 unmodified lines57 }58 59 /// Runs the benchmark for the given commands60 fn run(commands: &Vec<Command>, options: &HyperfineOptions) -> io::Result<Vec<BenchmarkResult>> {61+ let shell_spawning_time =61- let shell_spawning_time = mean_shell_spawning_time(&options.shell, &options.output_style, options.show_output)?;62+ mean_shell_spawning_time(&options.shell, &options.output_style, options.show_output)?;63 64 let mut timing_results = vec![];65 66 // Run the benchmarks124 unmodified lines191 }192 _ => {}193 };194 194- options.shell = matches.value_of("shell").unwrap_or(&options.shell).to_string();195+ options.shell = matches196+ .value_of("shell")197+ .unwrap_or(&options.shell)198+ .to_string();199 200 if matches.is_present("ignore-failure") {201 options.failure_action = CmdFailureAction::Ignore;202 }49 unmodified lines