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

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}'
This commit is contained in:
Ævar Arnfjörð Bjarmason authored and David Peter committed 2021-11-16 21:36:35 +01:00
1 parent abd0d335ab
commit 017d55a4a1
7 files changed
+103 -3

No files matched your search

+21 -2
View File
@@ -62,6 +62,12 @@ Perform at most \fImaxruns\fP (number) runs for each command. Default: no limit.
Perform exactly \fIruns\fP (number) runs for each command. If this option is not specified,
\fBhyperfine\fR automatically determines the number of runs.
.HP
\fB\-s\fR, \fB\-\-setup\fR \fIcmd\fP
.IP
Execute \fIcmd\fP once before each set of timing runs. This is useful
for compiling software or doing other one-off setup.
The \fB\-\-setup\fR option can only be specified once.
.HP
\fB\-p\fR, \fB\-\-prepare\fR \fIcmd...\fP
.IP
Execute \fIcmd\fP before each timing run. This is useful for clearing disk caches,
@@ -119,14 +125,15 @@ Example:
.IP
This performs benchmarks for 'gcc \-O2 main.cpp' and 'clang \-O2 main.cpp'.
.HP
\fB\-s\fR, \fB\-\-style\fR \fItype\fP
\fB\-\-style\fR \fItype\fP
.IP
Set output style \fItype\fP (default: auto). Set this to 'basic' to disable output
coloring and interactive elements. Set it to 'full' to enable all effects even
if no interactive terminal was detected. Set this to 'nocolor' to keep the
interactive output without any colors. Set this to 'color' to keep the colors
without any interactive output. Set this to 'none' to disable all the output
of the tool.
of the tool. In hyperfine versions v0.4.0..v1.12.0 this option took the \fB\-s\fR,
short option, which is now used by \fB\--setup\fR.
.HP
\fB\-S\fR, \fB\-\-shell\fR \fIshell\fP
.IP
@@ -207,6 +214,18 @@ Export the results of a parameter scan benchmark to a markdown table:
\fBhyperfine\fR \fB\-\-export\-markdown\fR output.md \fB\-\-parameter-scan\fR time 1 5 'sleep {time}'
.fi
.RE
.LP
Demonstrate when each of \fB\-\-setup\fR, \fB\-\-prepare\fR, \fIcmd\fP and \fB\-\-cleanup\fR will run:
.RS
.nf
\fBhyperfine\fR \fB\-L\fR n 1,2 \fB\-r\fR 2 \fB\-\-show-output\fR \\
\fB\-\-setup\fR 'echo setup n={n}' \\
\fB\-\-prepare\fR 'echo prepare={n}' \\
\fB\-\-cleanup\fR 'echo cleanup n={n}' \\
'echo command n={n}'
.fi
.RE
.RE
.SH AUTHOR
.LP
David Peter (sharkdp)