cli.rs
This file
Path
src/cli.rs
307 lines · 13.6 KiB · Rust
Last changed by
Make --time-unit help text more generic.Engineer-of-Efficiencybefore adoptionedb29f4
History of this fileTake it
Update dependenciesDavid Peterbefore adoptionf2f1dd9
lines 1–24why, one step back1use std::ffi::OsString;23use clap::{crate_version, AppSettings, Arg, ArgMatches, Command};45pub fn get_cli_arguments<'a, I, T>(args: I) -> ArgMatches6where7 I: IntoIterator<Item = T>,8 T: Into<OsString> + Clone + 'a,9{10 let command = build_command();11 command.get_matches_from(args)12}1314/// Build the clap command for parsing command line arguments15fn build_command() -> Command<'static> {16 Command::new("hyperfine")17 .version(crate_version!())18 .setting(AppSettings::DeriveDisplayOrder)19 .next_line_help(true)20 .hide_possible_values(true)21 .max_term_width(90)22 .about("A command-line benchmarking tool.")23 .arg(24 Arg::new("command")Switch to --shell=none/-N, do not change the defaultDavid Peterbefore adoption365ff25
lines 25–29why, one step back25 .help("The command to benchmark. This can be the name of an executable, a command \26 line like \"grep -i todo\" or a shell command like \"sleep 0.5 && echo test\". \27 The latter is only available if the shell is not explicitly disabled via \28 '--shell=none'. If multiple commands are given, hyperfine will show a \29 comparison of the respective runtimes.")Update dependenciesDavid Peterbefore adoptionf2f1dd9
lines 30–185why, one step back30 .required(true)31 .multiple_occurrences(true)32 .forbid_empty_values(true),33 )34 .arg(35 Arg::new("warmup")36 .long("warmup")37 .short('w')38 .takes_value(true)39 .value_name("NUM")40 .help(41 "Perform NUM warmup runs before the actual benchmark. This can be used \42 to fill (disk) caches for I/O-heavy programs.",43 ),44 )45 .arg(46 Arg::new("min-runs")47 .long("min-runs")48 .short('m')49 .takes_value(true)50 .value_name("NUM")51 .help("Perform at least NUM runs for each command (default: 10)."),52 )53 .arg(54 Arg::new("max-runs")55 .long("max-runs")56 .short('M')57 .takes_value(true)58 .value_name("NUM")59 .help("Perform at most NUM runs for each command. By default, there is no limit."),60 )61 .arg(62 Arg::new("runs")63 .long("runs")64 .conflicts_with_all(&["max-runs", "min-runs"])65 .short('r')66 .takes_value(true)67 .value_name("NUM")68 .help("Perform exactly NUM runs for each command. If this option is not specified, \69 hyperfine automatically determines the number of runs."),70 )71 .arg(72 Arg::new("setup")73 .long("setup")74 .short('s')75 .takes_value(true)76 .number_of_values(1)77 .value_name("CMD")78 .help(79 "Execute CMD before each set of timing runs. This is useful for \80 compiling your software with the provided parameters, or to do any \81 other work that should happen once before a series of benchmark runs, \82 not every time as would happen with the --prepare option."83 ),84 )85 .arg(86 Arg::new("prepare")87 .long("prepare")88 .short('p')89 .takes_value(true)90 .multiple_occurrences(true)91 .number_of_values(1)92 .value_name("CMD")93 .help(94 "Execute CMD before each timing run. This is useful for \95 clearing disk caches, for example.\nThe --prepare option can \96 be specified once for all commands or multiple times, once for \97 each command. In the latter case, each preparation command will \98 be run prior to the corresponding benchmark command.",99 ),100 )101 .arg(102 Arg::new("cleanup")103 .long("cleanup")104 .short('c')105 .takes_value(true)106 .value_name("CMD")107 .help(108 "Execute CMD after the completion of all benchmarking \109 runs for each individual command to be benchmarked. \110 This is useful if the commands to be benchmarked produce \111 artifacts that need to be cleaned up."112 ),113 )114 .arg(115 Arg::new("parameter-scan")116 .long("parameter-scan")117 .short('P')118 .takes_value(true)119 .allow_hyphen_values(true)120 .value_names(&["VAR", "MIN", "MAX"])121 .help(122 "Perform benchmark runs for each value in the range MIN..MAX. Replaces the \123 string '{VAR}' in each command by the current parameter value.\n\n \124 Example: hyperfine -P threads 1 8 'make -j {threads}'\n\n\125 This performs benchmarks for 'make -j 1', 'make -j 2', …, 'make -j 8'.\n\n\126 To have the value increase following different patterns, use shell arithmetics.\n\n \127 Example: hyperfine -P size 0 3 'sleep $((2**{size}))'\n\n\128 This performs benchmarks with power of 2 increases: 'sleep 1', 'sleep 2', 'sleep 4', …\n\129 The exact syntax may vary depending on your shell and OS."130 ),131 )132 .arg(133 Arg::new("parameter-step-size")134 .long("parameter-step-size")135 .short('D')136 .takes_value(true)137 .value_names(&["DELTA"])138 .requires("parameter-scan")139 .help(140 "This argument requires --parameter-scan to be specified as well. \141 Traverse the range MIN..MAX in steps of DELTA.\n\n \142 Example: hyperfine -P delay 0.3 0.7 -D 0.2 'sleep {delay}'\n\n\143 This performs benchmarks for 'sleep 0.3', 'sleep 0.5' and 'sleep 0.7'.",144 ),145 )146 .arg(147 Arg::new("parameter-list")148 .long("parameter-list")149 .short('L')150 .takes_value(true)151 .multiple_occurrences(true)152 .allow_hyphen_values(true)153 .value_names(&["VAR", "VALUES"])154 .conflicts_with_all(&["parameter-scan", "parameter-step-size"])155 .help(156 "Perform benchmark runs for each value in the comma-separated list VALUES. \157 Replaces the string '{VAR}' in each command by the current parameter value\158 .\n\nExample: hyperfine -L compiler gcc,clang '{compiler} -O2 main.cpp'\n\n\159 This performs benchmarks for 'gcc -O2 main.cpp' and 'clang -O2 main.cpp'.\n\n\160 The option can be specified multiple times to run benchmarks for all \161 possible parameter combinations.\n"162 ),163 )164 .arg(165 Arg::new("style")166 .long("style")167 .takes_value(true)168 .value_name("TYPE")169 .possible_values(&["auto", "basic", "full", "nocolor", "color", "none"])170 .help(171 "Set output style type (default: auto). Set this to 'basic' to disable output \172 coloring and interactive elements. Set it to 'full' to enable all effects \173 even if no interactive terminal was detected. Set this to 'nocolor' to \174 keep the interactive output without any colors. Set this to 'color' to keep \175 the colors without any interactive output. Set this to 'none' to disable all \176 the output of the tool.",177 ),178 )179 .arg(180 Arg::new("shell")181 .long("shell")182 .short('S')183 .takes_value(true)184 .value_name("SHELL")185 .overrides_with("shell")Switch to --shell=none/-N, do not change the defaultDavid Peterbefore adoption365ff25
lines 186–188why, one step back186 .help("Set the shell to use for executing benchmarked commands. This can be the \187 name or the path to the shell executable, or a full command line \188 like \"bash --norc\". It can also be set to \"default\" to explicitly select \Update warning textDavid Peterbefore adoption65932dd
line 189why, one step back189 the default shell on this platform. Finally, this can also be set to \Switch to --shell=none/-N, do not change the defaultDavid Peterbefore adoption365ff25
lines 190–198why, one step back190 \"none\" to disable the shell. In this case, commands will be executed \191 directly. They can still have arguments, but more complex things like \192 \"sleep 0.1; sleep 0.2\" are not possible without a shell.")193 )194 .arg(195 Arg::new("no-shell")196 .short('N')197 .conflicts_with_all(&["shell", "debug-mode"])198 .help("An alias for '--shell=none'.")Update dependenciesDavid Peterbefore adoptionf2f1dd9
lines 199–212why, one step back199 )200 .arg(201 Arg::new("ignore-failure")202 .long("ignore-failure")203 .short('i')204 .help("Ignore non-zero exit codes of the benchmarked programs."),205 )206 .arg(207 Arg::new("time-unit")208 .long("time-unit")209 .short('u')210 .takes_value(true)211 .value_name("UNIT")212 .possible_values(&["millisecond", "second"])Make --time-unit help text more generic.Engineer-of-Efficiencybefore adoptionedb29f4
lines 213–214why, one step back213 .help("Set the time unit to be used (default: second). Possible values: millisecond, second.\214 This option affects the standard output as well as all export formats except for CSV and JSON."),Update dependenciesDavid Peterbefore adoptionf2f1dd9
lines 215–220why, one step back215 )216 .arg(217 Arg::new("export-asciidoc")218 .long("export-asciidoc")219 .takes_value(true)220 .value_name("FILE")Add hints to all export optionsEngineer-of-Efficiencybefore adoption73f1e14
lines 221–222why, one step back221 .help("Export the timing summary statistics as an AsciiDoc table to the given FILE.\222 The output time unit is affected by the --time-unit option"),Update dependenciesDavid Peterbefore adoptionf2f1dd9
lines 223–229why, one step back223 )224 .arg(225 Arg::new("export-csv")226 .long("export-csv")227 .takes_value(true)228 .value_name("FILE")229 .help("Export the timing summary statistics as CSV to the given FILE. If you need \Add hints to all export optionsEngineer-of-Efficiencybefore adoption73f1e14
lines 230–231why, one step back230 the timing results for each individual run, use the JSON export format.\231 The output time unit is NOT affected by the --time-unit option, instead it is always seconds"),Update dependenciesDavid Peterbefore adoptionf2f1dd9
lines 232–237why, one step back232 )233 .arg(234 Arg::new("export-json")235 .long("export-json")236 .takes_value(true)237 .value_name("FILE")Add hints to all export optionsEngineer-of-Efficiencybefore adoption73f1e14
lines 238–239why, one step back238 .help("Export the timing summary statistics and timings of individual runs as JSON to the given FILE.\239 The output time unit is NOT affected by the --time-unit option, instead it is always seconds"),Update dependenciesDavid Peterbefore adoptionf2f1dd9
lines 240–245why, one step back240 )241 .arg(242 Arg::new("export-markdown")243 .long("export-markdown")244 .takes_value(true)245 .value_name("FILE")Add hints to all export optionsEngineer-of-Efficiencybefore adoption73f1e14
lines 246–247why, one step back246 .help("Export the timing summary statistics as a Markdown table to the given FILE.\247 The output time unit is affected by the --time-unit option"),Update dependenciesDavid Peterbefore adoptionf2f1dd9
lines 248–249why, one step back248 )249 .arg(Export of Emacs org-mode table supportPhilipp Paulweberbefore adoption2443383
lines 250–253why, one step back250 Arg::new("export-orgmode")251 .long("export-orgmode")252 .takes_value(true)253 .value_name("FILE")Add hints to all export optionsEngineer-of-Efficiencybefore adoption73f1e14
lines 254–255why, one step back254 .help("Export the timing summary statistics as a Emacs org-mode table to the given FILE.\255 The output time unit is affected by the --time-unit option"),Export of Emacs org-mode table supportPhilipp Paulweberbefore adoption2443383
lines 256–257why, one step back256 )257 .arg(Update dependenciesDavid Peterbefore adoptionf2f1dd9
lines 258–268why, one step back258 Arg::new("show-output")259 .long("show-output")260 .conflicts_with("style")261 .help(262 "Print the stdout and stderr of the benchmark instead of suppressing it. \263 This will increase the time it takes for benchmarks to run, \264 so it should only be used for debugging purposes or \265 when trying to benchmark output speed.",266 ),267 )268 .arg(Implement --output={null,pipe,<FILE>}Tavian Barnesbefore adoption277807c
lines 269–274why, one step back269 Arg::new("output")270 .long("output")271 .conflicts_with("show-output")272 .takes_value(true)273 .value_name("WHERE")274 .help(Clarify --output's help textTavian Barnesbefore adoptiondfd1046
lines 275–280why, one step back275 "Control where the output of the benchmark is redirected. <WHERE> can be:\n\n\276 null: Redirect output to /dev/null (the default). \277 Note that some programs like 'grep' detect when standard output is /dev/null \278 and apply certain optimizations. To avoid that, consider using \279 '--output=pipe'.\n\n\280 pipe: Feed the output through a pipe before discarding it.\n\n\Add --output=inherit as an alias for --show-outputTavian Barnesbefore adoptionecee9df
line 281why, one step back281 inherit: Don't redirect the output at all (same as '--show-output').\n\n\Implement --output={null,pipe,<FILE>}Tavian Barnesbefore adoption277807c
lines 282–285why, one step back282 <FILE>: Write the output to the given file.",283 ),284 )285 .arg(Update dependenciesDavid Peterbefore adoptionf2f1dd9
lines 286–307why, one step back286 Arg::new("command-name")287 .long("command-name")288 .short('n')289 .takes_value(true)290 .multiple_occurrences(true)291 .number_of_values(1)292 .value_name("NAME")293 .help("Give a meaningful name to a command. This can be specified multiple times \294 if several commands are benchmarked."),295 )296 .arg(297 Arg::new("debug-mode")298 .long("debug-mode")299 .hide(true)300 .help("Enable debug mode which does not actually run commands, but returns fake times when the command is 'sleep <time>'")301 )302}303304#[test]305fn verify_app() {306 build_command().debug_assert();307}