Skip to content

Expose HYPERFINE_ITERATION to prepare and conclude commands#882

Open
c-tonneslan wants to merge 1 commit into
sharkdp:masterfrom
c-tonneslan:iteration-env-in-prepare-conclude
Open

Expose HYPERFINE_ITERATION to prepare and conclude commands#882
c-tonneslan wants to merge 1 commit into
sharkdp:masterfrom
c-tonneslan:iteration-env-in-prepare-conclude

Conversation

@c-tonneslan
Copy link
Copy Markdown

Closes #781.

HYPERFINE_ITERATION was set only on the actual benchmarked command, so prepare/conclude saw an unset variable. The realistic use case in the issue (touch / process / rm files keyed by iteration) didn't work because every iteration's prepare and conclude saw the same empty value.

The change threads the same BenchmarkIteration through run_preparation_command and run_conclusion_command. Setup and cleanup stay on NonBenchmarkRun since they only run once per benchmark, not per iteration.

Verified with:

hyperfine --warmup 1 --runs 3 \
  --prepare 'echo "prep=${HYPERFINE_ITERATION}" >&2' \
  --conclude 'echo "conc=${HYPERFINE_ITERATION}" >&2' \
  --show-output 'echo "main=${HYPERFINE_ITERATION}"'

which now prints prep / main / conc lines all reading warmup-0, then 0, 1, 2.

Test in execution_order_tests covers warmup and the two benchmark iterations.

sharkdp#778 added the env var, but only set it on the actual benchmarked
command, not on prepare or conclude. So this didn't work as you'd
expect:

    hyperfine --prepare 'touch file${HYPERFINE_ITERATION}.dat' \
              'process file${HYPERFINE_ITERATION}.dat' \
              --conclude 'rm file${HYPERFINE_ITERATION}.dat'

In the prepare/conclude commands the variable was unset, so they
all touched and removed 'file.dat'.

The fix is to thread the same BenchmarkIteration through
run_preparation_command and run_conclusion_command. Setup and
cleanup keep NonBenchmarkRun since they only run once.

Closes sharkdp#781

Signed-off-by: Charlie Tonneslan <cst0520@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

${HYPERFINE_ITERATION} is not visible in prepare or conclude commands

1 participant