Format code using 'cargo fmt'
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Atul Bhosale · committed by David Peter · parent 523d8ce · Browse files · 2 files·+61 added−65 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
2 files+61 added−65 removed
- other:+61 added−65 removed
Provenance
- Commit
1317092- Tree
5725de3- Author
Atul Bhosale <atul1bhosale@gmail.com>- Committer
David Peter <sharkdp@users.noreply.github.com>- Parent
523d8ce
2 files changed+61 added−65 removed
modified:src/hyperfine/export/asciidoc.rs+48 added-39 removed
47 unmodified lines48 let unit_short_name = unittype.short_name();49 format!(50 "| Command | Mean [{unit}] | Min…Max [{unit}]\n",51 unit = unit_short_name52+ )52- ).into_bytes()53+ .into_bytes()54 }55 56 fn table_row(entry: &BenchmarkResult, unit: Unit) -> Vec<u8> {57 let form = |val| format_duration_value(val, Some(unit));58 format!(59 "| `{}`\n\60 | {} ± {}\n\61 | {}…{}\n",61- entry.command.replace("|", "\\|"),62- form(entry.mean).0, form(entry.stddev).0,63- form(entry.min).0, form(entry.max).064- ).into_bytes()62+ entry.command.replace("|", "\\|"),63+ form(entry.mean).0,64+ form(entry.stddev).0,65+ form(entry.min).0,66+ form(entry.max).067+ )68+ .into_bytes()69 }70 71 /// Ensure various options for the header generate correct results72 #[test]73 fn test_asciidoc_header() {74 let conms: Vec<u8> = "| Command | Mean [ms] | Min…Max [ms]\n".bytes().collect();71- let cons: Vec<u8> = "| Command | Mean [s] | Min…Max [s]\n".bytes().collect();75+ let cons: Vec<u8> = "| Command | Mean [s] | Min…Max [s]\n".bytes().collect();76 let genms = table_header(Unit::MilliSecond);73- let gens = table_header(Unit::Second);77+ let gens = table_header(Unit::Second);78 79 assert_eq!(conms, genms);80 assert_eq!(cons, gens);81 }8 unmodified lines90 0.005182013333333333, // user91 0.0, // system92 0.1003342584, // min93 0.10745223440000001, // max90- vec![ // times94+ vec![95+ // times96 0.1003342584,97 0.10745223440000001,93- 0.1069732794000000198+ 0.10697327940000001,99 ],95- None // param100+ None, // param101 );102 103 let expms = format!(104 "| `{}`\n\105 | {} ± {}\n\106 | {}…{}\n",107 result.command,103- Unit::MilliSecond.format(result.mean), Unit::MilliSecond.format(result.stddev),104- Unit::MilliSecond.format(result.min), Unit::MilliSecond.format(result.max)105- ).into_bytes();108+ Unit::MilliSecond.format(result.mean),109+ Unit::MilliSecond.format(result.stddev),110+ Unit::MilliSecond.format(result.min),111+ Unit::MilliSecond.format(result.max)112+ )113+ .into_bytes();114 let exps = format!(115 "| `{}`\n\116 | {} ± {}\n\117 | {}…{}\n",118 result.command,111- Unit::Second.format(result.mean), Unit::Second.format(result.stddev),112- Unit::Second.format(result.min), Unit::Second.format(result.max)113- ).into_bytes();119+ Unit::Second.format(result.mean),120+ Unit::Second.format(result.stddev),121+ Unit::Second.format(result.min),122+ Unit::Second.format(result.max)123+ )124+ .into_bytes();125 126 let genms = table_row(&result, Unit::MilliSecond);116- let gens = table_row(&result, Unit::Second);127+ let gens = table_row(&result, Unit::Second);128 129 assert_eq!(expms, genms);130 assert_eq!(exps, gens);131 }8 unmodified lines140 0.005182013333333333, // user141 0.0, // system142 0.1003342584, // min143 0.10745223440000001, // max133- vec![ // times144+ vec![145+ // times146 0.1003342584,147 0.10745223440000001,136- 0.10697327940000001148+ 0.10697327940000001,149 ],138- None // param150+ None, // param151 );152 let exps = format!(153 "| `sleep 1\\|`\n\154 | {} ± {}\n\155 | {}…{}\n",144- Unit::Second.format(result.mean), Unit::Second.format(result.stddev),145- Unit::Second.format(result.min), Unit::Second.format(result.max)146- ).into_bytes();147- let gens = table_row(&result, Unit::Second);156+ Unit::Second.format(result.mean),157+ Unit::Second.format(result.stddev),158+ Unit::Second.format(result.min),159+ Unit::Second.format(result.max)160+ )161+ .into_bytes();162+ let gens = table_row(&result, Unit::Second);163 164 assert_eq!(exps, gens);165 }166 10 unmodified lines177 3.0,178 4.0,179 5.0,180 6.0,166- vec![167- 7.0,168- 8.0,169- 9.0170- ],171- None181+ vec![7.0, 8.0, 9.0],182+ None,183 ),184 BenchmarkResult::new(185 String::from("command | 2"),186 11.0,1 unmodified line188 13.0,189 14.0,190 15.0,191 16.0,181- vec![182- 17.0,183- 18.0,184- 19.0185- ],186- None187- )192+ vec![17.0, 18.0, 19.0],193+ None,194+ ),195 ];196 // NOTE: only testing with s, s/ms is tested elsewhere197 let exps: String = String::from(198 "[cols=\"<,>,>\"]\n\7 unmodified lines206 | `command \\| 2`\n\207 | 11.000 ± 12.000\n\208 | 15.000…16.000\n\209 |===\n\203- ");204- let gens = String::from_utf8(exporter.serialize(&results, Some(Unit::Second)).unwrap()).unwrap();210+ ",211+ );212+ let gens =213+ String::from_utf8(exporter.serialize(&results, Some(Unit::Second)).unwrap()).unwrap();214 215 assert_eq!(exps, gens);216 }modified:src/hyperfine/benchmark.rs+13 added-26 removed
151 unmodified lines152 ) -> io::Result<TimingResult> {153 if let &Some(ref cmd) = command {154 let res = time_shell_command(shell, cmd, show_output, CmdFailureAction::RaiseError, None);155 if res.is_err() {156- return Err(io::Error::new(157- io::ErrorKind::Other,158- error_output159- ));156+ return Err(io::Error::new(io::ErrorKind::Other, error_output));157 }158 return res.map(|r| r.0);159 }160 Ok(TimingResult {161 ..Default::default()162 })166-163 }164 165 /// Run the command specified by `--prepare`.166 fn run_preparation_command(1 unmodified line168 command: &Option<Command>,169 show_output: bool,170 ) -> io::Result<TimingResult> {171 let error_output = "The preparation command terminated with a non-zero exit code. \176- Append ' || true' to the command if you are sure that this can be ignored.";172+ Append ' || true' to the command if you are sure that this can be ignored.";173 178- run_intermediate_command(179- shell,180- command,181- show_output,182- error_output183- )174+ run_intermediate_command(shell, command, show_output, error_output)175 }176 177 /// Run the command specified by `--cleanup`.178 fn run_cleanup_command(1 unmodified line180 command: &Option<Command>,181 show_output: bool,182 ) -> io::Result<TimingResult> {183 let error_output = "The cleanup command terminated with a non-zero exit code. \193- Append ' || true' to the command if you are sure that this can be ignored.";184+ Append ' || true' to the command if you are sure that this can be ignored.";185 195- run_intermediate_command(196- shell,197- command,198- show_output,199- error_output200- )186+ run_intermediate_command(shell, command, show_output, error_output)187 }188 189 /// Run the benchmark for a single shell command190 pub fn run_benchmark(188 unmodified lines379 380 println!(" ");381 382 // Run cleanup command383+ let cleanup_cmd =397- let cleanup_cmd = options398- .cleanup_command399- .as_ref()400- .map(|cleanup_command| match cmd.get_parameter() {401- Some((param, value)) => Command::new_parametrized(cleanup_command, param, value),402- None => Command::new(cleanup_command),403- });384+ options385+ .cleanup_command386+ .as_ref()387+ .map(|cleanup_command| match cmd.get_parameter() {388+ Some((param, value)) => Command::new_parametrized(cleanup_command, param, value),389+ None => Command::new(cleanup_command),390+ });391 run_cleanup_command(&options.shell, &cleanup_cmd, options.show_output)?;392 393 Ok(BenchmarkResult::new(394 cmd.get_shell_command(),10 unmodified lines