Skip to content
Latchkey

How to Post a Benchmark Comment on PRs in GitHub Actions

Benchmark numbers buried in logs get ignored; surfacing them as a PR comment makes regressions impossible to miss.

Run the benchmark, format the result into Markdown, and post it as a sticky comment that updates in place on each push.

Steps

  • Trigger on pull_request.
  • Run the benchmark and write a Markdown summary file.
  • Post it with a sticky-comment action keyed by a header.
  • Grant pull-requests: write so the comment can be created.

Workflow

.github/workflows/bench.yml
on: pull_request
permissions:
  pull-requests: write
jobs:
  bench:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - id: run
        run: |
          RESULT=$(./bench.sh)
          {
            echo "result<<EOF"
            echo "### Benchmark"
            echo "$RESULT"
            echo "EOF"
          } >> "${GITHUB_OUTPUT}"
      - uses: marocchino/sticky-pull-request-comment@v2
        with:
          header: bench
          message: ${{ steps.run.outputs.result }}

Gotchas

  • Shared CI runners are noisy; compare relative deltas, not absolute numbers, to avoid false alarms.
  • A sticky header keeps one comment instead of a new one per push.
  • Latchkey runs benchmarks on consistent, cheaper runners that retry on transient failures for steadier numbers.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →