Expose HYPERFINE_ITERATION to prepare and conclude commands#859
Conversation
Previously, the HYPERFINE_ITERATION env var was only set for the benchmarked command itself. Prepare and conclude commands ran with BenchmarkIteration::NonBenchmarkRun, so the variable was unset. Now prepare and conclude receive the same iteration value as the main command, so users can reference files or state per-iteration in their setup/teardown scripts. Fixes #781
This pull request was closed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #781
The `HYPERFINE_ITERATION` env var was only available in the benchmarked command, not in `--prepare` or `--conclude`. This meant you couldn't do per-iteration setup/teardown like:
```bash
hyperfine --runs 5
--prepare 'touch file${HYPERFINE_ITERATION}.dat'
'process file${HYPERFINE_ITERATION}.dat'
--conclude 'rm file${HYPERFINE_ITERATION}.dat'
```
The fix passes the current `BenchmarkIteration` through to prepare and conclude commands instead of `NonBenchmarkRun`. During warmup phases, the value is `warmup-N`, and during benchmark runs it's the iteration number (matching the main command).
Setup and cleanup commands still use `NonBenchmarkRun` since they run once per benchmark, not per iteration.
All 58 tests pass.