How to publish benchmark results with Git

Commit a selected run with the suite

From the suite repository root, record the benchmarks whose results you want to publish. Benched prints the run ID and the path to its JSON file.

benched run --results-dir benchmark-results
benched history --results-dir benchmark-results

Review and stage the new run file, then commit it with the page that uses it. The JSON records the suite revision and working-tree state at measurement time. If your Sphinx page is in docs/, it can read the tracked directory directly. Replace RUN_ID with the recorded ID.

.. benched:: ../benchmark-results
   :selector: RUN_ID

The standalone pandas and Polars example uses this layout for a single-run baseline table. Exploratory runs can keep the default .benched/results directory.

Append CI runs on a results branch

For frequent runs, give the publishing job its own branch in the suite repository. Create it once from the revision where you want the results history to begin.

git branch benchmark-history
git push origin benchmark-history

In a fresh CI checkout of the revision to measure, fetch the results branch and create a second worktree next to the suite. Run Benched from the suite root. Only its output directory points into the second worktree.

git fetch origin refs/heads/benchmark-history
git worktree add --detach ../benched-history FETCH_HEAD
benched run --results-dir ../benched-history/benchmark-results
git -C ../benched-history add -- benchmark-results/
git -C ../benched-history commit -m "Record benchmark run"
git -C ../benched-history push origin HEAD:refs/heads/benchmark-history
git -C ../benched-history rev-parse HEAD

The last command prints the results commit a documentation release can pin. Give the publishing job a Git identity and push access to the branch. If several machines produce runs, collect their JSON files into the results worktree and publish them in one job. If another publisher advances the branch first, fetch it in the results worktree, rebase the local results commit onto it, and push again. The existing run files retain their measured revisions and IDs.

Read a pinned results commit from Sphinx

Install the Git backend in the documentation environment and fetch the results branch into the local suite clone.

python -m pip install 'fsspec[git]'
git fetch origin refs/heads/benchmark-history

Run the build from the repository root. Replace RESULTS_COMMIT below with the full commit ID printed by the publisher. A shallow clone must also fetch that commit if it falls outside the available history.

.. benched:: git://RESULTS_COMMIT@benchmark-results
   :view: trend

For a baseline table use the same URL with benched-comparison and its :baseline: option. To inspect the pinned history from the command line, use benched history --results-dir "git://RESULTS_COMMIT@benchmark-results". If you run Sphinx outside the clone, set path under [tool.benched.storage_options] to the clone’s absolute path.

The Git backend reads the committed tree locally. New measurements go to a writable directory and become visible at a new Git commit after publication.