app.rs
This file
Path
src/app.rs
263 lines · 10.9 KiB · Rust
Last changed by
Add debug/mock modeDavid Peterbefore adoption6f51232
History of this fileTake it
Re-order importsDavid Peterbefore adoption9df6174
lines 1–2why, one step back1use std::ffi::OsString;2Flat directory/module structureDavid Peterbefore adoption30c381f
lines 3–4why, one step back3use clap::{crate_version, App, AppSettings, Arg, ArgMatches};4Introduce Commands structDavid Peterbefore adoptiona6baf49
line 5why, one step back5pub fn get_cli_arguments<'a, I, T>(args: I) -> ArgMatchesFlat directory/module structureDavid Peterbefore adoption30c381f
lines 6–7why, one step back6where7 I: IntoIterator<Item = T>,Update to clap 3David Peterbefore adoption80a9f51
line 8why, one step back8 T: Into<OsString> + Clone + 'a,Flat directory/module structureDavid Peterbefore adoption30c381f
lines 9–14why, one step back9{10 let app = build_app();11 app.get_matches_from(args)12}1314/// Build the clap app for parsing command line argumentsUpdate to clap 3David Peterbefore adoption80a9f51
line 15why, one step back15fn build_app() -> App<'static> {Flat directory/module structureDavid Peterbefore adoption30c381f
lines 16–19why, one step back16 App::new("hyperfine")17 .version(crate_version!())18 .setting(AppSettings::DeriveDisplayOrder)19 .setting(AppSettings::NextLineHelp)Update to clap 3David Peterbefore adoption80a9f51
line 20why, one step back20 .setting(AppSettings::HidePossibleValues)Flat directory/module structureDavid Peterbefore adoption30c381f
lines 21–23why, one step back21 .max_term_width(90)22 .about("A command-line benchmarking tool.")23 .arg(Update to clap 3David Peterbefore adoption80a9f51
lines 24–27why, one step back24 Arg::new("command")25 .help("Command to benchmark. This can be the name of an executable or a shell \26 command like \"sleep 0.5 && echo test\". If multiple commands are given, \27 hyperfine will show a comparison of the respective runtimes.")Flat directory/module structureDavid Peterbefore adoption30c381f
line 28why, one step back28 .required(true)Update to clap 3David Peterbefore adoption80a9f51
lines 29–30why, one step back29 .multiple_occurrences(true)30 .forbid_empty_values(true),Flat directory/module structureDavid Peterbefore adoption30c381f
lines 31–32why, one step back31 )32 .arg(Update to clap 3David Peterbefore adoption80a9f51
line 33why, one step back33 Arg::new("warmup")Flat directory/module structureDavid Peterbefore adoption30c381f
line 34why, one step back34 .long("warmup")Update to clap 3David Peterbefore adoption80a9f51
line 35why, one step back35 .short('w')Flat directory/module structureDavid Peterbefore adoption30c381f
lines 36–43why, one step back36 .takes_value(true)37 .value_name("NUM")38 .help(39 "Perform NUM warmup runs before the actual benchmark. This can be used \40 to fill (disk) caches for I/O-heavy programs.",41 ),42 )43 .arg(Update to clap 3David Peterbefore adoption80a9f51
line 44why, one step back44 Arg::new("min-runs")Flat directory/module structureDavid Peterbefore adoption30c381f
line 45why, one step back45 .long("min-runs")Update to clap 3David Peterbefore adoption80a9f51
line 46why, one step back46 .short('m')Flat directory/module structureDavid Peterbefore adoption30c381f
lines 47–51why, one step back47 .takes_value(true)48 .value_name("NUM")49 .help("Perform at least NUM runs for each command (default: 10)."),50 )51 .arg(Update to clap 3David Peterbefore adoption80a9f51
line 52why, one step back52 Arg::new("max-runs")Flat directory/module structureDavid Peterbefore adoption30c381f
line 53why, one step back53 .long("max-runs")Update to clap 3David Peterbefore adoption80a9f51
line 54why, one step back54 .short('M')Flat directory/module structureDavid Peterbefore adoption30c381f
lines 55–59why, one step back55 .takes_value(true)56 .value_name("NUM")57 .help("Perform at most NUM runs for each command. By default, there is no limit."),58 )59 .arg(Update to clap 3David Peterbefore adoption80a9f51
line 60why, one step back60 Arg::new("runs")Flat directory/module structureDavid Peterbefore adoption30c381f
lines 61–62why, one step back61 .long("runs")62 .conflicts_with_all(&["max-runs", "min-runs"])Update to clap 3David Peterbefore adoption80a9f51
line 63why, one step back63 .short('r')Flat directory/module structureDavid Peterbefore adoption30c381f
lines 64–69why, one step back64 .takes_value(true)65 .value_name("NUM")66 .help("Perform exactly NUM runs for each command. If this option is not specified, \67 hyperfine automatically determines the number of runs."),68 )69 .arg(Update to clap 3David Peterbefore adoption80a9f51
line 70why, one step back70 Arg::new("setup")Add --setup (-s) option, like --prepare but runs once per batchÆvar Arnfjörð Bjarmasonbefore adoption017d55a
line 71why, one step back71 .long("setup")Update to clap 3David Peterbefore adoption80a9f51
line 72why, one step back72 .short('s')Add --setup (-s) option, like --prepare but runs once per batchÆvar Arnfjörð Bjarmasonbefore adoption017d55a
lines 73–78why, one step back73 .takes_value(true)74 .number_of_values(1)75 .value_name("CMD")76 .help(77 "Execute CMD before each set of timing runs. This is useful for \78 compiling your software with the provided parameters, or to do any \Expand execution order testsDavid Peterbefore adoption5df981a
line 79why, one step back79 other work that should happen once before a series of benchmark runs, \Add --setup (-s) option, like --prepare but runs once per batchÆvar Arnfjörð Bjarmasonbefore adoption017d55a
lines 80–83why, one step back80 not every time as would happen with the --prepare option."81 ),82 )83 .arg(Update to clap 3David Peterbefore adoption80a9f51
line 84why, one step back84 Arg::new("prepare")Flat directory/module structureDavid Peterbefore adoption30c381f
line 85why, one step back85 .long("prepare")Update to clap 3David Peterbefore adoption80a9f51
line 86why, one step back86 .short('p')Flat directory/module structureDavid Peterbefore adoption30c381f
line 87why, one step back87 .takes_value(true)Update to clap 3David Peterbefore adoption80a9f51
line 88why, one step back88 .multiple_occurrences(true)Flat directory/module structureDavid Peterbefore adoption30c381f
lines 89–99why, one step back89 .number_of_values(1)90 .value_name("CMD")91 .help(92 "Execute CMD before each timing run. This is useful for \93 clearing disk caches, for example.\nThe --prepare option can \94 be specified once for all commands or multiple times, once for \95 each command. In the latter case, each preparation command will \96 be run prior to the corresponding benchmark command.",97 ),98 )99 .arg(Update to clap 3David Peterbefore adoption80a9f51
line 100why, one step back100 Arg::new("cleanup")Flat directory/module structureDavid Peterbefore adoption30c381f
line 101why, one step back101 .long("cleanup")Update to clap 3David Peterbefore adoption80a9f51
line 102why, one step back102 .short('c')Flat directory/module structureDavid Peterbefore adoption30c381f
lines 103–112why, one step back103 .takes_value(true)104 .value_name("CMD")105 .help(106 "Execute CMD after the completion of all benchmarking \107 runs for each individual command to be benchmarked. \108 This is useful if the commands to be benchmarked produce \109 artifacts that need to be cleaned up."110 ),111 )112 .arg(Update to clap 3David Peterbefore adoption80a9f51
line 113why, one step back113 Arg::new("parameter-scan")Flat directory/module structureDavid Peterbefore adoption30c381f
line 114why, one step back114 .long("parameter-scan")Update to clap 3David Peterbefore adoption80a9f51
line 115why, one step back115 .short('P')Flat directory/module structureDavid Peterbefore adoption30c381f
lines 116–122why, one step back116 .takes_value(true)117 .allow_hyphen_values(true)118 .value_names(&["VAR", "MIN", "MAX"])119 .help(120 "Perform benchmark runs for each value in the range MIN..MAX. Replaces the \121 string '{VAR}' in each command by the current parameter value.\n\n \122 Example: hyperfine -P threads 1 8 'make -j {threads}'\n\n\Document different increase pattern for -PClément Jolybefore adoption5c6b302
lines 123–127why, one step back123 This performs benchmarks for 'make -j 1', 'make -j 2', …, 'make -j 8'.\n\n\124 To have the value increase following different patterns, use shell arithmetics.\n\n \125 Example: hyperfine -P size 0 3 'sleep $((2**{size}))'\n\n\126 This performs benchmarks with power of 2 increases: 'sleep 1', 'sleep 2', 'sleep 4', …\n\127 The exact syntax may vary depending on your shell and OS."Flat directory/module structureDavid Peterbefore adoption30c381f
lines 128–130why, one step back128 ),129 )130 .arg(Update to clap 3David Peterbefore adoption80a9f51
line 131why, one step back131 Arg::new("parameter-step-size")Flat directory/module structureDavid Peterbefore adoption30c381f
line 132why, one step back132 .long("parameter-step-size")Update to clap 3David Peterbefore adoption80a9f51
line 133why, one step back133 .short('D')Flat directory/module structureDavid Peterbefore adoption30c381f
lines 134–144why, one step back134 .takes_value(true)135 .value_names(&["DELTA"])136 .requires("parameter-scan")137 .help(138 "This argument requires --parameter-scan to be specified as well. \139 Traverse the range MIN..MAX in steps of DELTA.\n\n \140 Example: hyperfine -P delay 0.3 0.7 -D 0.2 'sleep {delay}'\n\n\141 This performs benchmarks for 'sleep 0.3', 'sleep 0.5' and 'sleep 0.7'.",142 ),143 )144 .arg(Update to clap 3David Peterbefore adoption80a9f51
line 145why, one step back145 Arg::new("parameter-list")Flat directory/module structureDavid Peterbefore adoption30c381f
line 146why, one step back146 .long("parameter-list")Update to clap 3David Peterbefore adoption80a9f51
line 147why, one step back147 .short('L')Flat directory/module structureDavid Peterbefore adoption30c381f
line 148why, one step back148 .takes_value(true)Update to clap 3David Peterbefore adoption80a9f51
line 149why, one step back149 .multiple_occurrences(true)Flat directory/module structureDavid Peterbefore adoption30c381f
lines 150–162why, one step back150 .allow_hyphen_values(true)151 .value_names(&["VAR", "VALUES"])152 .conflicts_with_all(&["parameter-scan", "parameter-step-size"])153 .help(154 "Perform benchmark runs for each value in the comma-separated list VALUES. \155 Replaces the string '{VAR}' in each command by the current parameter value\156 .\n\nExample: hyperfine -L compiler gcc,clang '{compiler} -O2 main.cpp'\n\n\157 This performs benchmarks for 'gcc -O2 main.cpp' and 'clang -O2 main.cpp'.\n\n\158 The option can be specified multiple times to run benchmarks for all \159 possible parameter combinations.\n"160 ),161 )162 .arg(Update to clap 3David Peterbefore adoption80a9f51
line 163why, one step back163 Arg::new("style")Flat directory/module structureDavid Peterbefore adoption30c381f
lines 164–177why, one step back164 .long("style")165 .takes_value(true)166 .value_name("TYPE")167 .possible_values(&["auto", "basic", "full", "nocolor", "color", "none"])168 .help(169 "Set output style type (default: auto). Set this to 'basic' to disable output \170 coloring and interactive elements. Set it to 'full' to enable all effects \171 even if no interactive terminal was detected. Set this to 'nocolor' to \172 keep the interactive output without any colors. Set this to 'color' to keep \173 the colors without any interactive output. Set this to 'none' to disable all \174 the output of the tool.",175 ),176 )177 .arg(Update to clap 3David Peterbefore adoption80a9f51
line 178why, one step back178 Arg::new("shell")Flat directory/module structureDavid Peterbefore adoption30c381f
line 179why, one step back179 .long("shell")Update to clap 3David Peterbefore adoption80a9f51
line 180why, one step back180 .short('S')Flat directory/module structureDavid Peterbefore adoption30c381f
lines 181–186why, one step back181 .takes_value(true)182 .value_name("SHELL")183 .overrides_with("shell")184 .help("Set the shell to use for executing benchmarked commands."),185 )186 .arg(Update to clap 3David Peterbefore adoption80a9f51
line 187why, one step back187 Arg::new("ignore-failure")Flat directory/module structureDavid Peterbefore adoption30c381f
line 188why, one step back188 .long("ignore-failure")Update to clap 3David Peterbefore adoption80a9f51
line 189why, one step back189 .short('i')Flat directory/module structureDavid Peterbefore adoption30c381f
lines 190–192why, one step back190 .help("Ignore non-zero exit codes of the benchmarked programs."),191 )192 .arg(Update to clap 3David Peterbefore adoption80a9f51
line 193why, one step back193 Arg::new("time-unit")Flat directory/module structureDavid Peterbefore adoption30c381f
line 194why, one step back194 .long("time-unit")Update to clap 3David Peterbefore adoption80a9f51
line 195why, one step back195 .short('u')Flat directory/module structureDavid Peterbefore adoption30c381f
lines 196–201why, one step back196 .takes_value(true)197 .value_name("UNIT")198 .possible_values(&["millisecond", "second"])199 .help("Set the time unit to be used. Possible values: millisecond, second."),200 )201 .arg(Update to clap 3David Peterbefore adoption80a9f51
line 202why, one step back202 Arg::new("export-asciidoc")Flat directory/module structureDavid Peterbefore adoption30c381f
lines 203–208why, one step back203 .long("export-asciidoc")204 .takes_value(true)205 .value_name("FILE")206 .help("Export the timing summary statistics as an AsciiDoc table to the given FILE."),207 )208 .arg(Update to clap 3David Peterbefore adoption80a9f51
line 209why, one step back209 Arg::new("export-csv")Flat directory/module structureDavid Peterbefore adoption30c381f
lines 210–216why, one step back210 .long("export-csv")211 .takes_value(true)212 .value_name("FILE")213 .help("Export the timing summary statistics as CSV to the given FILE. If you need \214 the timing results for each individual run, use the JSON export format."),215 )216 .arg(Update to clap 3David Peterbefore adoption80a9f51
line 217why, one step back217 Arg::new("export-json")Flat directory/module structureDavid Peterbefore adoption30c381f
lines 218–223why, one step back218 .long("export-json")219 .takes_value(true)220 .value_name("FILE")221 .help("Export the timing summary statistics and timings of individual runs as JSON to the given FILE."),222 )223 .arg(Update to clap 3David Peterbefore adoption80a9f51
line 224why, one step back224 Arg::new("export-markdown")Flat directory/module structureDavid Peterbefore adoption30c381f
lines 225–230why, one step back225 .long("export-markdown")226 .takes_value(true)227 .value_name("FILE")228 .help("Export the timing summary statistics as a Markdown table to the given FILE."),229 )230 .arg(Update to clap 3David Peterbefore adoption80a9f51
line 231why, one step back231 Arg::new("show-output")Flat directory/module structureDavid Peterbefore adoption30c381f
lines 232–241why, one step back232 .long("show-output")233 .conflicts_with("style")234 .help(235 "Print the stdout and stderr of the benchmark instead of suppressing it. \236 This will increase the time it takes for benchmarks to run, \237 so it should only be used for debugging purposes or \238 when trying to benchmark output speed.",239 ),240 )241 .arg(Update to clap 3David Peterbefore adoption80a9f51
line 242why, one step back242 Arg::new("command-name")Flat directory/module structureDavid Peterbefore adoption30c381f
line 243why, one step back243 .long("command-name")Update to clap 3David Peterbefore adoption80a9f51
line 244why, one step back244 .short('n')Flat directory/module structureDavid Peterbefore adoption30c381f
line 245why, one step back245 .takes_value(true)Update to clap 3David Peterbefore adoption80a9f51
line 246why, one step back246 .multiple_occurrences(true)Flat directory/module structureDavid Peterbefore adoption30c381f
lines 247–248why, one step back247 .number_of_values(1)248 .value_name("NAME")Update to clap 3David Peterbefore adoption80a9f51
lines 249–250why, one step back249 .help("Give a meaningful name to a command. This can be specified multiple times \250 if several commands are benchmarked."),Flat directory/module structureDavid Peterbefore adoption30c381f
line 251why, one step back251 )Add debug/mock modeDavid Peterbefore adoption6f51232
lines 252–257why, one step back252 .arg(253 Arg::new("debug-mode")254 .long("debug-mode")255 .hide(true)256 .help("Enable debug mode which does not actually run commands, but returns fake times when the command is 'sleep <time>'")257 )Update to clap 3David Peterbefore adoption80a9f51
lines 258–262why, one step back258}259260#[test]261fn verify_app() {262 build_app().debug_assert();Flat directory/module structureDavid Peterbefore adoption30c381f
line 263why, one step back263}