Skip to content

Expose HYPERFINE_ITERATION to prepare and conclude commands#859

Closed
ghost wants to merge 1 commit intomasterfrom
unknown repository
Closed

Expose HYPERFINE_ITERATION to prepare and conclude commands#859
ghost wants to merge 1 commit intomasterfrom
unknown repository

Conversation

@ghost
Copy link
Copy Markdown

@ghost ghost commented Mar 22, 2026

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.

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
@ghost ghost closed this by deleting the head repository Mar 26, 2026
This pull request was closed.
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

0 participants