How to embed a BenchX comparison in Sphinx

This run compares the time to sum an Int64 series in pandas and Polars. Both libraries received the same integers. BenchX timed the sum after constructing the series and alternated the two implementations over six rounds.

polars 2.2.0 compared with pandas 3.1.1

Benchmark

size

Quantity

pandas 3.1.1 (median)

polars 2.2.0 (median)

Ratio

Paired effect

Verdict

bench_series_sum

1000

wall-time

2.25e-06 s

1.743e-07 s

0.0775×

-92.17%

improved [baseline: env-mismatch, contender: env-mismatch]

bench_series_sum

100000

wall-time

8.986e-06 s

7.136e-06 s

0.794×

-18.08%

no-change-detected [baseline: env-mismatch, contender: env-mismatch]

bench_series_sum

1000000

wall-time

8.745e-05 s

7.801e-05 s

0.892×

-2.27%

no-change-detected [baseline: env-mismatch, contender: env-mismatch]

Method: benchx/paired-relative/v2

Each timing is the median of the per-attempt medians used in the comparison. The ratio divides the contender timing by the baseline timing. BenchX calculates the paired effect across rounds and supplies the verdict. A negative effect means less time for this operation. BenchX flagged a difference between the requested and observed worker environments on both sides of this run.

Embed a saved comparison

Enable benched.sphinx in your Sphinx extensions. Give the directive a BenchX variants comparison saved with bx compare --json and the directory of measurement files from the same run. Both paths are relative to the page. To select a single workload, supply its exact name.

.. benched-comparison:: comparison.json
   :results: results
   :benchmark: bench_series_sum

The directive reads version 0.1.0 comparison and measurement documents with the observation median estimator. It also accepts a ZIP of the measurement JSON files at the archive root. Sphinx builds the table offline and uses its theme to render it. An indeterminate verdict includes BenchX’s reason. An incomplete set of referenced files produces a build error.

Publish the comparison as standalone HTML

From the directory containing the downloaded example files, run:

benched report --benchx-comparison comparison.json measurements.zip --output site

Open or publish site/index.html. The file contains the same table as the Sphinx directive and works offline. To publish one workload from a larger comparison, add --benchmark followed by its exact name.

Show measurements from a single benchmark

Enable benched.sphinx and point benched-measurements at a BenchX 0.1.0 measurement JSON file. For a directory or ZIP, place the JSON files at its root. Select a workload by exact name with :benchmark:. Use :run: to select the BenchX run key when the source contains measurements from multiple matching runs.

.. benched-measurements:: measurements.zip
   :benchmark: bench_series_sum
   :run: series-sum

Each row shows the attempt, workload parameters, quantity, unit, and status. Benched displays each estimate supplied by the producer. For an attempt with only observations, it takes their median. Censored attempts show the recorded bound. Partial, skipped, and failed attempts retain their recorded reason.

Show the 36 recorded series-sum attempts
BenchX measurements for series-sum

Benchmark

implementation

size

Attempt

Quantity

Statistic

Value

Unit

Status

bench_series_sum

'pandas'

1000

urn:benchx:attempt:40d3eef33b12b56b:0

wall-time

Observation median

2.247e-06

s

success

bench_series_sum

'pandas'

1000

urn:benchx:attempt:90a1bd5108940771:0

wall-time

Observation median

2.109e-06

s

success

bench_series_sum

'pandas'

1000

urn:benchx:attempt:dc9cd9491f39d11c:0

wall-time

Observation median

2.855e-06

s

success

bench_series_sum

'pandas'

1000

urn:benchx:attempt:7c6f81bf15104059:0

wall-time

Observation median

2.252e-06

s

success

bench_series_sum

'pandas'

1000

urn:benchx:attempt:6de4e130d6f9186b:0

wall-time

Observation median

2.048e-06

s

success

bench_series_sum

'pandas'

1000

urn:benchx:attempt:3c686ee5a71c3705:0

wall-time

Observation median

2.254e-06

s

success

bench_series_sum

'pandas'

100000

urn:benchx:attempt:40d3eef33b12b56b:1

wall-time

Observation median

9.949e-06

s

success

bench_series_sum

'pandas'

100000

urn:benchx:attempt:90a1bd5108940771:1

wall-time

Observation median

8.681e-06

s

success

bench_series_sum

'pandas'

100000

urn:benchx:attempt:dc9cd9491f39d11c:1

wall-time

Observation median

9.395e-06

s

success

bench_series_sum

'pandas'

100000

urn:benchx:attempt:7c6f81bf15104059:1

wall-time

Observation median

9.279e-06

s

success

bench_series_sum

'pandas'

100000

urn:benchx:attempt:6de4e130d6f9186b:1

wall-time

Observation median

8.565e-06

s

success

bench_series_sum

'pandas'

100000

urn:benchx:attempt:3c686ee5a71c3705:1

wall-time

Observation median

8.693e-06

s

success

bench_series_sum

'pandas'

1000000

urn:benchx:attempt:40d3eef33b12b56b:2

wall-time

Observation median

9.549e-05

s

success

bench_series_sum

'pandas'

1000000

urn:benchx:attempt:90a1bd5108940771:2

wall-time

Observation median

7.847e-05

s

success

bench_series_sum

'pandas'

1000000

urn:benchx:attempt:dc9cd9491f39d11c:2

wall-time

Observation median

8.597e-05

s

success

bench_series_sum

'pandas'

1000000

urn:benchx:attempt:7c6f81bf15104059:2

wall-time

Observation median

9.688e-05

s

success

bench_series_sum

'pandas'

1000000

urn:benchx:attempt:6de4e130d6f9186b:2

wall-time

Observation median

8.893e-05

s

success

bench_series_sum

'pandas'

1000000

urn:benchx:attempt:3c686ee5a71c3705:2

wall-time

Observation median

7.972e-05

s

success

bench_series_sum

'polars'

1000

urn:benchx:attempt:0957c2878f6e69ea:0

wall-time

Observation median

1.855e-07

s

success

bench_series_sum

'polars'

1000

urn:benchx:attempt:b9a8832d09d08c17:0

wall-time

Observation median

1.555e-07

s

success

bench_series_sum

'polars'

1000

urn:benchx:attempt:68a3649bedb37034:0

wall-time

Observation median

2.15e-07

s

success

bench_series_sum

'polars'

1000

urn:benchx:attempt:f7c5f08322edf7c2:0

wall-time

Observation median

1.609e-07

s

success

bench_series_sum

'polars'

1000

urn:benchx:attempt:8628140049d6a8a2:0

wall-time

Observation median

1.927e-07

s

success

bench_series_sum

'polars'

1000

urn:benchx:attempt:efe8847a36754759:0

wall-time

Observation median

1.631e-07

s

success

bench_series_sum

'polars'

100000

urn:benchx:attempt:0957c2878f6e69ea:1

wall-time

Observation median

7.055e-06

s

success

bench_series_sum

'polars'

100000

urn:benchx:attempt:b9a8832d09d08c17:1

wall-time

Observation median

7.828e-06

s

success

bench_series_sum

'polars'

100000

urn:benchx:attempt:68a3649bedb37034:1

wall-time

Observation median

9.927e-06

s

success

bench_series_sum

'polars'

100000

urn:benchx:attempt:f7c5f08322edf7c2:1

wall-time

Observation median

6.388e-06

s

success

bench_series_sum

'polars'

100000

urn:benchx:attempt:8628140049d6a8a2:1

wall-time

Observation median

7.216e-06

s

success

bench_series_sum

'polars'

100000

urn:benchx:attempt:efe8847a36754759:1

wall-time

Observation median

6.232e-06

s

success

bench_series_sum

'polars'

1000000

urn:benchx:attempt:0957c2878f6e69ea:2

wall-time

Observation median

8.245e-05

s

success

bench_series_sum

'polars'

1000000

urn:benchx:attempt:b9a8832d09d08c17:2

wall-time

Observation median

7.531e-05

s

success

bench_series_sum

'polars'

1000000

urn:benchx:attempt:68a3649bedb37034:2

wall-time

Observation median

0.0001222

s

success

bench_series_sum

'polars'

1000000

urn:benchx:attempt:f7c5f08322edf7c2:2

wall-time

Observation median

7.982e-05

s

success

bench_series_sum

'polars'

1000000

urn:benchx:attempt:8628140049d6a8a2:2

wall-time

Observation median

7.619e-05

s

success

bench_series_sum

'polars'

1000000

urn:benchx:attempt:efe8847a36754759:2

wall-time

Observation median

7.484e-05

s

success

Reproduce the example

BenchX’s pyperf adapter runs the same bench_series_sum(implementation, size) function used by the pytest example. The module constructs the six Int64 series when it loads. Each timed call looks up the requested series and sums it. Run the following from the Benched checkout with pandas, Polars, and BenchX installed. The saved example used pandas 3.1.1, Polars 2.2.0, and BenchX at 84595be.

mkdir -p build/series-sum
export BENCHX_SETUP_FILE="$PWD/build/series-sum/packages.json"
python -c 'import json; from importlib.metadata import version; print(json.dumps({"packages": {p: version(p) for p in ("pandas", "polars")}}))' > "$BENCHX_SETUP_FILE"
bx compare . --profile variants --adapter pyperf \
    --suite docs/examples/pytest/series_sum.py --vary implementation \
    --baseline "'pandas'" --rounds 6 --processes 1 --values 3 --min-time 0.01 --warmups 1 \
    --project benched --run-key series-sum --no-ingest --out build/series-sum/results \
    --json > build/series-sum/comparison.json

The setup file records installed versions with the measurements. Benched uses the version when a side’s parameter value matches a package name. The downloadable example retains all 36 timing measurements. The hostname was anonymized and local artifact references removed before regenerating the comparison. Benchmark source · Measurement files · Comparison document