Skip to content
Myr

Add --setup (-s) option, like --prepare but runs once per batch

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

Add a --setup option for the use-case of wanting to do one-off setup before a set of benchmarks, not the once-per-test setup that --prepare does. This is useful for the cases noted in the updated documentation. Per the feedback on https://github.com/sharkdp/hyperfine/pull/448 this new "--setup" option will steal the "-s" short option from "--style" (initially this was called "--build" and used the non-conflicting "-b"). Potential future work: I'd prefer if this and --cleanup took N number of commands, so you could do e.g.: hyperfine -L rev master,next \ -b 'git worktree add /tmp/test-{r}' \ -b 'make -C /tmp/test-{r} all' \ 'make -C /tmp/test-{r} test' \ -c 'git worktree remove /tmp/test-{r}' I.e. a shortcut around not providing these with &&, which makes things a bit more readable. But the --cleanup option doesn't do that, so let's just go with what it's doing for consistency, so for this you'll now need to do: hyperfine -L rev master,next \ -b 'git worktree add /tmp/test-{r} && make -C /tmp/test-{r} all' \ 'make -C /tmp/test-{r} test' \ -c 'git worktree remove /tmp/test-{r}'

authored by Ævar Arnfjörð Bjarmason · committed by David Peter · parent abd0d33 · Browse files · 7 files+103 added−3 removed
This commit

State

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

Diff stats

7 files+103 added−3 removed

  • tests:+38 added−0 removed
  • other:+65 added−3 removed

7 files+103 added−3 removed

modified:doc/hyperfine.1+21 added-2 removed
60 unmodified lines
61.IP62Perform exactly \fIruns\fP (number) runs for each command. If this option is not specified,63\fBhyperfine\fR automatically determines the number of runs.64.HP65\fB\-s\fR, \fB\-\-setup\fR \fIcmd\fP66.IP67Execute \fIcmd\fP once before each set of timing runs. This is useful68for compiling software or doing other one-off setup.69The \fB\-\-setup\fR option can only be specified once.70.HP71\fB\-p\fR, \fB\-\-prepare\fR \fIcmd...\fP72.IP73Execute \fIcmd\fP before each timing run. This is useful for clearing disk caches,74for example.
49 unmodified lines
124.RE125.IP126This performs benchmarks for 'gcc \-O2 main.cpp' and 'clang \-O2 main.cpp'.127.HP122\fB\-s\fR, \fB\-\-style\fR \fItype\fP128\fB\-\-style\fR \fItype\fP129.IP130Set output style \fItype\fP (default: auto). Set this to 'basic' to disable output131coloring and interactive elements. Set it to 'full' to enable all effects even132if no interactive terminal was detected. Set this to 'nocolor' to keep the133interactive output without any colors. Set this to 'color' to keep the colors134without any interactive output. Set this to 'none' to disable all the output129of the tool.135of the tool. In hyperfine versions v0.4.0..v1.12.0 this option took the \fB\-s\fR,136short option, which is now used by \fB\--setup\fR.137.HP138\fB\-S\fR, \fB\-\-shell\fR \fIshell\fP139.IP140Set the \fIshell\fP to use for executing benchmarked commands.
72 unmodified lines
213.nf214\fBhyperfine\fR \fB\-\-export\-markdown\fR output.md \fB\-\-parameter-scan\fR time 1 5 'sleep {time}'215.fi216.RE217.LP218Demonstrate when each of \fB\-\-setup\fR, \fB\-\-prepare\fR, \fIcmd\fP and \fB\-\-cleanup\fR will run:219.RS220.nf221\fBhyperfine\fR \fB\-L\fR n 1,2 \fB\-r\fR 2 \fB\-\-show-output\fR \\222 \fB\-\-setup\fR 'echo setup n={n}' \\223 \fB\-\-prepare\fR 'echo prepare={n}' \\224 \fB\-\-cleanup\fR 'echo cleanup n={n}' \\225 'echo command n={n}'226.fi227.RE228.RE229.SH AUTHOR230.LP231David Peter (sharkdp)232.LP
2 unmodified lines
modified:src/app.rs+14 added-1 removed
72 unmodified lines
73 .help("Perform exactly NUM runs for each command. If this option is not specified, \74 hyperfine automatically determines the number of runs."),75 )76 .arg(77 Arg::with_name("setup")78 .long("setup")79 .short("s")80 .takes_value(true)81 .number_of_values(1)82 .value_name("CMD")83 .help(84 "Execute CMD before each set of timing runs. This is useful for \85 compiling your software with the provided parameters, or to do any \86 other work that should happen once before a series of benchmark runs,\87 not every time as would happen with the --prepare option."88 ),89 )90 .arg(91 Arg::with_name("prepare")92 .long("prepare")93 .short("p")94 .takes_value(true)
73 unmodified lines
168 )169 .arg(170 Arg::with_name("style")171 .long("style")158 .short("s")172 .takes_value(true)173 .value_name("TYPE")174 .possible_values(&["auto", "basic", "full", "nocolor", "color", "none"])175 .help(
85 unmodified lines
modified:src/benchmark.rs+18 added
183 unmodified lines
184 ..Default::default()185 })186}187188/// Run the command specified by `--setup`.189fn run_setup_command(190 shell: &Shell,191 command: &Option<Command<'_>>,192 show_output: bool,193) -> io::Result<TimingResult> {194 let error_output = "The setup command terminated with a non-zero exit code. \195 Append ' || true' to the command if you are sure that this can be ignored.";196197 run_intermediate_command(shell, command, show_output, error_output)198}199200/// Run the command specified by `--prepare`.201fn run_preparation_command(202 shell: &Shell,203 command: &Option<Command<'_>>,
70 unmodified lines
274 };275 Command::new_parametrized(None, preparation_command, cmd.get_parameters().clone())276 });277278 // Run setup command279 let setup_cmd = options.setup_command.as_ref().map(|setup_command| {280 Command::new_parametrized(None, setup_command, cmd.get_parameters().clone())281 });282 run_setup_command(&options.shell, &setup_cmd, options.show_output)?;283284 // Warmup phase285 if options.warmup_count > 0 {286 let progress_bar = if options.output_style != OutputStyleOption::Disabled {287 Some(get_progress_bar(
235 unmodified lines
modified:src/main.rs+2 added
191 unmodified lines
192 }193 (None, None) => {}194 };195196 options.setup_command = matches.value_of("setup").map(String::from);197198 options.preparation_command = matches199 .values_of("prepare")200 .map(|values| values.map(String::from).collect::<Vec<String>>());201
255 unmodified lines
modified:src/options.rs+4 added
112 unmodified lines
113114 /// Whether or not to ignore non-zero exit codes115 pub failure_action: CmdFailureAction,116117 /// Command to run before each batch of timing runs118 pub setup_command: Option<String>,119120 /// Command to run before each timing run121 pub preparation_command: Option<Vec<String>>,122123 /// Command to run after each benchmark
24 unmodified lines
148 warmup_count: 0,149 runs: Runs::default(),150 min_time_sec: 3.0,151 failure_action: CmdFailureAction::RaiseError,152 setup_command: None,153 preparation_command: None,154 cleanup_command: None,155 output_style: OutputStyleOption::Full,156 shell: Shell::default(),
50 unmodified lines
modified:tests/integration_tests.rs+38 added
68 unmodified lines
69 self.arg(self.get_command(output));70 self71 }7273 fn setup(&mut self, output: &str) -> &mut Self {74 self.arg("--setup");75 self.command(output)76 }7778 fn prepare(&mut self, output: &str) -> &mut Self {79 self.arg("--prepare");80 self.command(output)81 }
70 unmodified lines
152 .run();153}154155#[test]156fn setup_commands_are_executed_before_each_series_of_timing_runs() {157 ExecutionOrderTest::new()158 .arg("--runs=2")159 .setup("setup")160 .command("command 1")161 .command("command 2")162 .expect_output("setup")163 .expect_output("command 1")164 .expect_output("command 1")165 .expect_output("setup")166 .expect_output("command 2")167 .expect_output("command 2")168 .run();169}170171#[test]172fn prepare_commands_are_executed_before_each_timing_run() {173 ExecutionOrderTest::new()174 .arg("--runs=2")175 .prepare("prepare")
26 unmodified lines
202 .run();203}204205#[test]206fn setup_prepare_cleanup_combined() {207 ExecutionOrderTest::new()208 .arg("--runs=2")209 .setup("make")210 .prepare("make testclean")211 .command("make test")212 .cleanup("make clean")213 .expect_output("make")214 .expect_output("make testclean")215 .expect_output("make test")216 .expect_output("make testclean")217 .expect_output("make test")218 .expect_output("make clean")219 .run();220}221222#[test]223fn single_parameter_value() {224 ExecutionOrderTest::new()225 .arg("--runs=2")226 .arg("--parameter-list")
37 unmodified lines
modified:CHANGELOG.md+6 added
1# unreleased23## Features45- Added `--setup` (`s`) option that can be used to run `make all` or6 similar. It runs once per set of tests, like `--cleanup` (`c`).78## Changes910- The `-s` short option for `--style` has been usurped by the new11 `--setup` option.1213## Bugfixes1415## Other16
267 unmodified lines