From 9292488cf7161093aa9545ef203381c77ad29050 Mon Sep 17 00:00:00 2001 From: Marco Edward Gorelli <33491632+MarcoGorelli@users.noreply.github.com> Date: Fri, 27 Nov 2026 19:06:25 +0000 Subject: [PATCH 1/5] WIP: initial conversion of the pandas-asv example --- .github/workflows/docs.yml | 1 + docs/examples.md | 4 +- examples/pandas-asv/.gitignore | 4 + examples/pandas-asv/README.md | 167 +++++++++++++++++++++++++++ examples/pandas-asv/benchx.conf.json | 17 +++ examples/pandas-asv/describe_env.py | 16 +++ 6 files changed, 207 insertions(+), 2 deletions(-) create mode 100644 examples/pandas-asv/.gitignore create mode 100644 examples/pandas-asv/README.md create mode 100644 examples/pandas-asv/benchx.conf.json create mode 100644 examples/pandas-asv/describe_env.py diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index 1a65d3b..dfb7a7e 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -51,6 +51,7 @@ jobs: - example: pyperf-suite - example: matmul-params requires: numpy torch --index-url https://download.pytorch.org/whl/cpu + - example: pandas-asv env: EXAMPLE: ${{ matrix.example }} steps: diff --git a/docs/examples.md b/docs/examples.md index d24cfc6..41dd59d 100644 --- a/docs/examples.md +++ b/docs/examples.md @@ -39,6 +39,8 @@ in this repository. `bx bench`, the local store, and `bx series` / `bx history`. - [`matmul-params`](examples/matmul-params.md) — one benchmark function with several parameter combinations (sizes, numpy and torch), and a numpy-vs-torch comparison with `bx compare`. +- [`pandas-asv`](examples/pandas-asv.md) -- cross-environment comparison run of a specific benchmark + from the pandas ASV suite, under two pandas versions. Also shows how to run existing ASV benchmarks. ## Additional, cookbook-style examples @@ -47,8 +49,6 @@ Standalone, runnable examples of local usage live in a separate repository, - `examples/numpy-venvs` — cross-environment comparison across two virtual environments ([UC-04](use-cases/UC-04-cross-env.md)). -- `examples/pandas-asv` -- cross-environment comparison run of a specific benchmark - from the pandas ASV suite. Also shows how to run existing ASV benchmarks. - `examples/arrow/demo/run.sh` — CMake + Google Benchmark walkthrough covering comparison profiles on a small C++ suite. - `examples/arrow/archery-local` — target provider walkthrough diff --git a/examples/pandas-asv/.gitignore b/examples/pandas-asv/.gitignore new file mode 100644 index 0000000..603dcac --- /dev/null +++ b/examples/pandas-asv/.gitignore @@ -0,0 +1,4 @@ +.venv-*/ +out/ +pandas/ +__pycache__/ diff --git a/examples/pandas-asv/README.md b/examples/pandas-asv/README.md new file mode 100644 index 0000000..cd5eb13 --- /dev/null +++ b/examples/pandas-asv/README.md @@ -0,0 +1,167 @@ +# pandas-asv: one pandas asv benchmark, two pandas versions + +One benchmark from pandas' own [asv](https://asv.readthedocs.io) suite, run unchanged by +`bx bench PATH --adapter asv` under two pandas versions, each in its own virtual environment, +alternated round by round, then compared. The asv adapter reads asv's benchmark format as a +language (discovery, `params`, `setup`, `setup_cache`, asv's benchmark version hash) and times it +with pyperf: neither asv nor asv_runner is installed. + +The suite is pandas' `asv_bench/` at one tag (`v3.1.1`), the same for both sides; only the +installed pandas differs. That is +[UC-04](https://github.com/benchx-dev/benchx/blob/main/docs/use-cases/UC-04-cross-env.md), +"fixed branch, comparing environments", driven the same way as `examples/numpy-venvs`. + +The case is `strings.Methods.time_lower('str')`: one parameter combination of one benchmark. +`dtype="str"` is object dtype in pandas 2.x and the pyarrow-backed string dtype from pandas 3.0, +so the two sides are expected to differ. + +## Run it + +You need [`uv`](https://docs.astral.sh/uv/), git, and network access the first time. Then run the +steps below from this directory. A run takes under a minute after the venvs are cached. + +Everything the steps create is in `pandas/`, `.venv-a`, `.venv-b` and `out/`, all git-ignored. +Start by removing what an earlier run left: + +```sh +$ rm -rf pandas .venv-a .venv-b out +``` + +benchx itself runs only inside the two venvs, and step 2 installs it there, from this checkout +(`../..`). Outside a checkout, install `benchx` from PyPI there instead. + +## What it does + +### 1. Fetch the suite + +A shallow, sparse clone of pandas at `v3.1.1`, with only `asv_bench/` +checked out (a few MB). Nothing is built: the benchmarks import the pandas installed in each +venv, and each case runs from a scratch directory, so the unbuilt checkout cannot shadow it. + +```sh +$ git -c advice.detachedHead=false clone -q --depth 1 --branch v3.1.1 --filter=blob:none --sparse https://github.com/pandas-dev/pandas.git pandas +$ git -C pandas sparse-checkout set asv_bench +$ git -C pandas rev-parse --short HEAD +``` + +### 2. Prepare two venvs + +`.venv-a` with pandas 2.3.3 and `.venv-b` with pandas 3.1.1, each +with pyarrow, pyperf and benchx. benchx builds nothing: the user prepares both environments. + +```sh +$ uv venv -q --python 3.12 .venv-a +$ uv pip install -q --python .venv-a/bin/python pandas==2.3.3 pyarrow pyperf -e ../.. +$ uv venv -q --python 3.12 .venv-b +$ uv pip install -q --python .venv-b/bin/python pandas==3.1.1 pyarrow pyperf -e ../.. +``` + +### 3. Run the caller's loop + +For each of the 4 rounds (the fewest that give a verdict), one call +per side, in its venv, with one slot per call: + +```sh +slot=0 +for round in 0 1 2 3; do + for side in a:2.3.3 b:3.1.1; do + . ".venv-${side%:*}/bin/activate" + bx bench pandas/asv_bench --adapter asv "strings.Methods.time_lower('str')" \ + --run-key pandas-asv --label "env=pandas-${side#*:}" \ + --round "$round" --slot "$slot" --out out/pandas-asv + slot=$((slot + 1)) + done +done +``` + +`pandas/asv_bench` holds `asv.conf.json`, whose `benchmark_dir` is the suite; its checkout +is the target. The exact case name selects one parameter combination; `--filter REGEX` +(asv's `--bench`) would select by pattern instead. Modules the venv cannot import (no +matplotlib, scipy, ...) are listed on stderr and skipped. Each call prints a table, one for +each of the 8 calls: + +```text +case median mean ± sd min .. max n status +---------------------------------------- -------- ------------------- -------------------- -- ----------------------------------- +strings.Methods.time_lower [dtype='str'] 890.2 us 937.6 us ± 122.9 us 835.2 us .. 1.202 ms 10 success [setup-per-call-unbatched] +``` + +### 4. Compare + +The sides are told apart by the `env` label, and the two `grep` lines fail the +example if the comparison was refused, or if it does not name `deps.pandas` as the difference: + +```sh +$ bx compare --run pandas-asv --profile environments --label env --baseline pandas-2.3.3 | tee out/compare.txt +$ grep -q 'differs:.*deps\.pandas' out/compare.txt +$ ! grep -q 'failed invariants' out/compare.txt +``` + +```text +run pandas-asv profile environments baseline pandas-2.3.3 contender pandas-3.1.1 + differs: coordinates.environment.system.deps.pandas, coordinates.environment.system.deps.sha256 + caveats: baseline: setup-per-call-unbatched, contender: setup-per-call-unbatched + +IMPROVED (1) + strings.Methods.time_lower wall-time effect -85.40% noise 1.76% rounds=4 +``` + +(The numbers vary from run to run.) `effect` is the contender against the baseline, averaged +over the rounds' paired medians: `-85.40%` means pandas 3.1.1 takes about 15% of the time +pandas 2.3.3 does, so about 7x faster, well beyond the round-to-round `noise`. `differs` +names the environment facts that tell the sides apart: `deps.pandas` is the version the +collector printed, and `deps.sha256` is the hash of the collector's whole output, which +changes whenever any of its facts do. Here numpy and pyarrow are the same on both sides, so +pandas is the one difference. + +### 5. List the series + +One per environment, because the collected pandas version is part of +a series' identity. Every point carries the suite's revision (pandas `v3.1.1`), whichever +pandas it ran under: the target is the checkout the benchmarks come from, and what varies is +the environment, recorded by the collector. + +```sh +$ bx series --quantity wall-time +``` + +## How it is configured + +`benchx.conf.json` is found by walking up from the working directory, so `bx` reads it when run +from here: + +- `adapter`: the harness (`asv`) and its precision, in pyperf's terms: 2 processes (asv's + rounds) × 5 values (asv's repeat), 1 warmup, loops calibrated. Flags such as `--processes`, + `--values`, `--min-time` and `--loops` override them per call. What neither gives comes from + each benchmark's own `repeat`, `number`, `sample_time` and `warmup_time`. +- `collectors.deps`: `describe_env.py`, a **context collector**. benchx runs it once per call, + in the environment the call runs in, and it prints the pandas, numpy and pyarrow it imports. + That lands in each result's `environment.system.deps`, which is how the `environments` + comparison knows what differs between the sides. +- `paths`: the store and the results go in `out/`, so `bx series` shows this run only. + `$BENCHX_HOME` would relocate the store over this setting: do not set it. + +Each result also records the installed project's version (`provenance.info.asv.installed`) and +asv's hash of the benchmark's code (`protocol.asv.benchmark_version`), so editing the benchmark +starts a new series. + +## Caveats + +- **`setup-per-call-unbatched`.** `Methods` has a `setup`, so, as in asv_runner >= 0.3.0, every + timed call sees fresh state: one call per loop, setup re-run between calls outside the timer. + For a ~100 µs call that timing includes some timer overhead, and the result is flagged. A + benchmark whose calls leave the set-up state intact can declare `setup_scope = "sample"`. +- **Memory benchmarks** (`peakmem_*`, `mem_*`) and other non-`time_*` types are listed and + skipped. +- **Unstable boot time.** pyperf's `boot_time` metadata is part of `environment.system`, which + the `environments` profile uses to tell sides apart. On hosts where the kernel's boot time + drifts (seen on WSL2), calls with the same label can then become separate sides, and the + comparison fails the `two-sides` invariant. This is a benchx issue, not specific to asv. + +## What is in this directory + +| File | Role | +|---|---| +| `README.md` | this walk-through, which is also the script: it is what the example runs | +| `benchx.conf.json` | the project file: the adapter and its precision, the `deps` collector, the paths | +| `describe_env.py` | the collector: prints the pandas, numpy and pyarrow this Python imports | diff --git a/examples/pandas-asv/benchx.conf.json b/examples/pandas-asv/benchx.conf.json new file mode 100644 index 0000000..ba18fdf --- /dev/null +++ b/examples/pandas-asv/benchx.conf.json @@ -0,0 +1,17 @@ +{ + "schema_version": "benchx/config/0.1.0", + "project": "pandas", + "adapter": { + "name": "asv", + "precision": { + "repetitions": { "mode": "fixed", "levels": [{ "unit": "process", "n": 2 }, { "unit": "value", "n": 5 }] }, + "warmup": { "mode": "count", "n_warmup": 1 } + } + }, + "collectors": { + "deps": { + "command": ["python", "{root}/describe_env.py"] + } + }, + "paths": { "store": "out/store.parquet", "results": "out" } +} diff --git a/examples/pandas-asv/describe_env.py b/examples/pandas-asv/describe_env.py new file mode 100644 index 0000000..2650951 --- /dev/null +++ b/examples/pandas-asv/describe_env.py @@ -0,0 +1,16 @@ +"""The collector: print the pandas this Python imports, and the libraries that decide how +fast it is. + +benchx.conf.json runs it once per call, in the environment the call runs in, so the two sides +can only differ here if their environments do. It prints the same text for the same +environment: no paths, no timestamps. +""" + +import json + +import numpy +import pandas +import pyarrow + +print(json.dumps({"summary": {"pandas": pandas.__version__, "numpy": numpy.__version__, + "pyarrow": pyarrow.__version__}}, sort_keys=True)) From 50d0dfd41f7e26f5bbcd6bbb36dcbfdd4942f17f Mon Sep 17 00:00:00 2001 From: Evgeni Burovski Date: Fri, 4 Dec 2026 08:37:49 +0100 Subject: [PATCH 2/5] DOC: update/expand the pandas-asv example --- docs/examples.md | 15 +- examples/pandas-asv/README.md | 340 ++++++++++++++++++++++++++-------- 2 files changed, 274 insertions(+), 81 deletions(-) diff --git a/docs/examples.md b/docs/examples.md index 41dd59d..03809b6 100644 --- a/docs/examples.md +++ b/docs/examples.md @@ -35,12 +35,15 @@ so that core `benchx` remains cloud-free and CI-vendor-neutral: The sources of these examples live in [`examples/`](https://github.com/benchx-dev/benchx/tree/main/examples) in this repository. -- [`pyperf-suite`](examples/pyperf-suite.md) -- timing a suite of Python functions with - `bx bench`, the local store, and `bx series` / `bx history`. -- [`matmul-params`](examples/matmul-params.md) — one benchmark function with several parameter - combinations (sizes, numpy and torch), and a numpy-vs-torch comparison with `bx compare`. -- [`pandas-asv`](examples/pandas-asv.md) -- cross-environment comparison run of a specific benchmark - from the pandas ASV suite, under two pandas versions. Also shows how to run existing ASV benchmarks. +- [`pyperf-suite`](examples/pyperf-suite.md) + Demonstrates `benchx` basics: timing a suite of Python functions with `bx bench`, the local store, and `bx series` / `bx history`. +- [`matmul-params`](examples/matmul-params.md) + Demonstrates running parametrized benchmarks, and comparisons across *variants*: a single + benchmark function with several parameter combinations (sizes, numpy and torch), and a + numpy-vs-torch comparison with `bx compare`. +- [`pandas-asv`](examples/pandas-asv.md) + Demonstrates a *cross-environment* comparison run of a specific benchmark from the pandas + ASV suite, under two pandas versions. Also shows how to run existing ASV benchmarks. ## Additional, cookbook-style examples diff --git a/examples/pandas-asv/README.md b/examples/pandas-asv/README.md index cd5eb13..87a3f53 100644 --- a/examples/pandas-asv/README.md +++ b/examples/pandas-asv/README.md @@ -1,25 +1,27 @@ # pandas-asv: one pandas asv benchmark, two pandas versions -One benchmark from pandas' own [asv](https://asv.readthedocs.io) suite, run unchanged by -`bx bench PATH --adapter asv` under two pandas versions, each in its own virtual environment, -alternated round by round, then compared. The asv adapter reads asv's benchmark format as a -language (discovery, `params`, `setup`, `setup_cache`, asv's benchmark version hash) and times it -with pyperf: neither asv nor asv_runner is installed. - -The suite is pandas' `asv_bench/` at one tag (`v3.1.1`), the same for both sides; only the -installed pandas differs. That is +In this example, we work out a cross-environment comparison: we take one benchmark from +pandas' own benchmark suite, and run it unchanged under two pandas versions, each in its +own virtual environment. + +The pandas benchmarks are written in the [asv](https://asv.readthedocs.io) format. We +therefore use the _asv adapter_, `--adapter asv`, which reads benchmarks in the asv's +format as a language (discovery, `params`, `setup`, `setup_cache`, asv's benchmark version +hash) and times it with `pyperf`: neither `asv` nor `asv_runner` are installed or invoked! + +Specifically, the benchmark is from pandas' `asv_bench/` at one tag (`v3.1.1`), the same +for both sides; only the installed pandas differs. That is [UC-04](https://github.com/benchx-dev/benchx/blob/main/docs/use-cases/UC-04-cross-env.md), -"fixed branch, comparing environments", driven the same way as `examples/numpy-venvs`. +"fixed branch, comparing environments". The case is `strings.Methods.time_lower('str')`: one parameter combination of one benchmark. `dtype="str"` is object dtype in pandas 2.x and the pyarrow-backed string dtype from pandas 3.0, so the two sides are expected to differ. -## Run it +## Set up the benchmark You need [`uv`](https://docs.astral.sh/uv/), git, and network access the first time. Then run the steps below from this directory. A run takes under a minute after the venvs are cached. - Everything the steps create is in `pandas/`, `.venv-a`, `.venv-b` and `out/`, all git-ignored. Start by removing what an earlier run left: @@ -27,15 +29,12 @@ Start by removing what an earlier run left: $ rm -rf pandas .venv-a .venv-b out ``` -benchx itself runs only inside the two venvs, and step 2 installs it there, from this checkout -(`../..`). Outside a checkout, install `benchx` from PyPI there instead. - -## What it does - ### 1. Fetch the suite -A shallow, sparse clone of pandas at `v3.1.1`, with only `asv_bench/` -checked out (a few MB). Nothing is built: the benchmarks import the pandas installed in each +We make a shallow, sparse clone of pandas at `v3.1.1`, with only `asv_bench/` checked out. +We do not build `pandas` itself, we only get the benchmark from the source checkout. + +Nothing is built: the benchmarks import the pandas installed in each venv, and each case runs from a scratch directory, so the unbuilt checkout cannot shadow it. ```sh @@ -44,10 +43,13 @@ $ git -C pandas sparse-checkout set asv_bench $ git -C pandas rev-parse --short HEAD ``` + ### 2. Prepare two venvs -`.venv-a` with pandas 2.3.3 and `.venv-b` with pandas 3.1.1, each -with pyarrow, pyperf and benchx. benchx builds nothing: the user prepares both environments. +We prepare two virtual environments, where each has its own `pandas` version: + `.venv-a` with pandas 2.3.3 and `.venv-b` with pandas 3.1.1. +In each environment, we also need to install `benchx` and its dependencies, `pyperf` +and `pyarrow` (strictly speaking, `pyarrow` is an optional dependency for `benchx`). ```sh $ uv venv -q --python 3.12 .venv-a @@ -56,16 +58,38 @@ $ uv venv -q --python 3.12 .venv-b $ uv pip install -q --python .venv-b/bin/python pandas==3.1.1 pyarrow pyperf -e ../.. ``` -### 3. Run the caller's loop +Note the `-e ../..` stanza: here we install `benchx` in the editable mode (`-e`), from +the source tree two levels below the root of the `benchx` source tree (so that `../..` +is the `benchx` root). + +From outside of the `benchx` checkout, install it from PyPI instead: replace +`-e ../..` by `benchx` in the `uv pip install` incantations above. + + +## Run the caller's loop For each of the 4 rounds (the fewest that give a verdict), one call -per side, in its venv, with one slot per call: +per side, in its venv, with one slot per call. + +Note the parameters to `bx bench` calls: +- `--adapter asv` tells `benchx` that the benchmarks are written in the `asv` format; +- the `"strings.Methods.time_lower('str')"` argument selects a single benchmark; +- `--run-key pandas-asv` groups all runs under the same _run key_: having the same + run-key is essential, the name `pandas-asv` is arbitrary; +- each call has an explicit `--round` and `--slot` to place it into the comparison + sequence, `abababab`; +- we manage the _slot_ count manually in the loop. +- `--label` argument tells the sides of the comparison apart. To arrange the + sequence as `abbaabba` instead of `abababa`, we would modify the `--slot` and `--label` + values accordingly. + +Taking this all together, we run ```sh slot=0 for round in 0 1 2 3; do for side in a:2.3.3 b:3.1.1; do - . ".venv-${side%:*}/bin/activate" + source ".venv-${side%:*}/bin/activate" bx bench pandas/asv_bench --adapter asv "strings.Methods.time_lower('str')" \ --run-key pandas-asv --label "env=pandas-${side#*:}" \ --round "$round" --slot "$slot" --out out/pandas-asv @@ -74,61 +98,248 @@ for round in 0 1 2 3; do done ``` -`pandas/asv_bench` holds `asv.conf.json`, whose `benchmark_dir` is the suite; its checkout -is the target. The exact case name selects one parameter combination; `--filter REGEX` -(asv's `--bench`) would select by pattern instead. Modules the venv cannot import (no -matplotlib, scipy, ...) are listed on stderr and skipped. Each call prints a table, one for -each of the 8 calls: - ```text +measuring benchmarks on /home/ev-br/temp/bx/pandas (round 0, slot 0, env=pandas-2.3.3) +precision: 2 rounds x 5 repeat (config: /home/ev-br/temp/bx/benchx.conf.json) +asv: skipped module benchmarks.io.excel: ModuleNotFoundError: No module named 'odf' +asv: skipped module benchmarks.io.sql: ModuleNotFoundError: No module named 'sqlalchemy' +asv: skipped module benchmarks.plotting: ModuleNotFoundError: No module named 'matplotlib' +asv: skipped module benchmarks.sparse: ModuleNotFoundError: No module named 'scipy' +asv: skipped module benchmarks.timeseries: ModuleNotFoundError: No module named 'pandas.tseries.converter' +caveats: setup-per-call-unbatched +case median mean ± sd min .. max n status +---------------------------------------- -------- ------------------- ------------------ -- ------- +strings.Methods.time_lower [dtype='str'] 873.2 us 870.9 us ± 11.51 us 854 us .. 893.3 us 10 success + +2 result(s) -> out/pandas-asv (order sha256:a01470f7248c) +run-key: pandas-asv +/home/ev-br/temp/bx/out/store.parquet: ingested 2, duplicate 0 +measuring benchmarks on /home/ev-br/temp/bx/pandas (round 0, slot 1, env=pandas-3.1.1) +precision: 2 rounds x 5 repeat (config: /home/ev-br/temp/bx/benchx.conf.json) +asv: skipped module benchmarks.io.excel: ModuleNotFoundError: No module named 'odf' +asv: skipped module benchmarks.io.sql: ModuleNotFoundError: No module named 'sqlalchemy' +asv: skipped module benchmarks.plotting: ModuleNotFoundError: No module named 'matplotlib' +asv: skipped module benchmarks.sparse: ModuleNotFoundError: No module named 'scipy' +asv: skipped module benchmarks.timeseries: ModuleNotFoundError: No module named 'pandas.tseries.converter' +caveats: setup-per-call-unbatched +case median mean ± sd min .. max n status +---------------------------------------- -------- ------------------- -------------------- -- ------- +strings.Methods.time_lower [dtype='str'] 115.7 us 117.4 us ± 6.868 us 110.6 us .. 130.9 us 10 success + +2 result(s) -> out/pandas-asv (order sha256:756a45a5887e) +run-key: pandas-asv +/home/ev-br/temp/bx/out/store.parquet: ingested 2, duplicate 0 +measuring benchmarks on /home/ev-br/temp/bx/pandas (round 1, slot 2, env=pandas-2.3.3) +precision: 2 rounds x 5 repeat (config: /home/ev-br/temp/bx/benchx.conf.json) +asv: skipped module benchmarks.io.excel: ModuleNotFoundError: No module named 'odf' +asv: skipped module benchmarks.io.sql: ModuleNotFoundError: No module named 'sqlalchemy' +asv: skipped module benchmarks.plotting: ModuleNotFoundError: No module named 'matplotlib' +asv: skipped module benchmarks.sparse: ModuleNotFoundError: No module named 'scipy' +asv: skipped module benchmarks.timeseries: ModuleNotFoundError: No module named 'pandas.tseries.converter' +caveats: setup-per-call-unbatched case median mean ± sd min .. max n status ----------------------------------------- -------- ------------------- -------------------- -- ----------------------------------- -strings.Methods.time_lower [dtype='str'] 890.2 us 937.6 us ± 122.9 us 835.2 us .. 1.202 ms 10 success [setup-per-call-unbatched] +---------------------------------------- -------- ------------------- -------------------- -- ------- +strings.Methods.time_lower [dtype='str'] 863.6 us 864.9 us ± 45.79 us 809.8 us .. 920.6 us 10 success + +2 result(s) -> out/pandas-asv (order sha256:71ecadc61c5a) +run-key: pandas-asv +/home/ev-br/temp/bx/out/store.parquet: ingested 2, duplicate 0 +measuring benchmarks on /home/ev-br/temp/bx/pandas (round 1, slot 3, env=pandas-3.1.1) +precision: 2 rounds x 5 repeat (config: /home/ev-br/temp/bx/benchx.conf.json) +asv: skipped module benchmarks.io.excel: ModuleNotFoundError: No module named 'odf' +asv: skipped module benchmarks.io.sql: ModuleNotFoundError: No module named 'sqlalchemy' +asv: skipped module benchmarks.plotting: ModuleNotFoundError: No module named 'matplotlib' +asv: skipped module benchmarks.sparse: ModuleNotFoundError: No module named 'scipy' +asv: skipped module benchmarks.timeseries: ModuleNotFoundError: No module named 'pandas.tseries.converter' +caveats: setup-per-call-unbatched +case median mean ± sd min .. max n status +---------------------------------------- -------- ------------------- -------------------- -- ------- +strings.Methods.time_lower [dtype='str'] 112.7 us 113.7 us ± 6.271 us 106.2 us .. 125.9 us 10 success + +2 result(s) -> out/pandas-asv (order sha256:5b9871fcdf1a) +run-key: pandas-asv +/home/ev-br/temp/bx/out/store.parquet: ingested 2, duplicate 0 +measuring benchmarks on /home/ev-br/temp/bx/pandas (round 2, slot 4, env=pandas-2.3.3) +precision: 2 rounds x 5 repeat (config: /home/ev-br/temp/bx/benchx.conf.json) +asv: skipped module benchmarks.io.excel: ModuleNotFoundError: No module named 'odf' +asv: skipped module benchmarks.io.sql: ModuleNotFoundError: No module named 'sqlalchemy' +asv: skipped module benchmarks.plotting: ModuleNotFoundError: No module named 'matplotlib' +asv: skipped module benchmarks.sparse: ModuleNotFoundError: No module named 'scipy' +asv: skipped module benchmarks.timeseries: ModuleNotFoundError: No module named 'pandas.tseries.converter' +caveats: setup-per-call-unbatched +case median mean ± sd min .. max n status +---------------------------------------- -------- ----------------- -------------------- -- ------- +strings.Methods.time_lower [dtype='str'] 866.3 us 869 us ± 9.716 us 859.7 us .. 892.6 us 10 success + +2 result(s) -> out/pandas-asv (order sha256:e3393238c05e) +run-key: pandas-asv +/home/ev-br/temp/bx/out/store.parquet: ingested 2, duplicate 0 +measuring benchmarks on /home/ev-br/temp/bx/pandas (round 2, slot 5, env=pandas-3.1.1) +precision: 2 rounds x 5 repeat (config: /home/ev-br/temp/bx/benchx.conf.json) +asv: skipped module benchmarks.io.excel: ModuleNotFoundError: No module named 'odf' +asv: skipped module benchmarks.io.sql: ModuleNotFoundError: No module named 'sqlalchemy' +asv: skipped module benchmarks.plotting: ModuleNotFoundError: No module named 'matplotlib' +asv: skipped module benchmarks.sparse: ModuleNotFoundError: No module named 'scipy' +asv: skipped module benchmarks.timeseries: ModuleNotFoundError: No module named 'pandas.tseries.converter' +caveats: setup-per-call-unbatched +case median mean ± sd min .. max n status +---------------------------------------- -------- ------------------- ------------------ -- ------- +strings.Methods.time_lower [dtype='str'] 114.1 us 116.3 us ± 7.748 us 108.9 us .. 130 us 10 success + +2 result(s) -> out/pandas-asv (order sha256:72b1813c69c2) +run-key: pandas-asv +/home/ev-br/temp/bx/out/store.parquet: ingested 2, duplicate 0 +measuring benchmarks on /home/ev-br/temp/bx/pandas (round 3, slot 6, env=pandas-2.3.3) +precision: 2 rounds x 5 repeat (config: /home/ev-br/temp/bx/benchx.conf.json) +asv: skipped module benchmarks.io.excel: ModuleNotFoundError: No module named 'odf' +asv: skipped module benchmarks.io.sql: ModuleNotFoundError: No module named 'sqlalchemy' +asv: skipped module benchmarks.plotting: ModuleNotFoundError: No module named 'matplotlib' +asv: skipped module benchmarks.sparse: ModuleNotFoundError: No module named 'scipy' +asv: skipped module benchmarks.timeseries: ModuleNotFoundError: No module named 'pandas.tseries.converter' +caveats: setup-per-call-unbatched +case median mean ± sd min .. max n status +---------------------------------------- -------- ------------------ -------------------- -- ------- +strings.Methods.time_lower [dtype='str'] 859.3 us 863.9 us ± 12.7 us 851.8 us .. 892.1 us 10 success + +2 result(s) -> out/pandas-asv (order sha256:3a2a1eca9ceb) +run-key: pandas-asv +/home/ev-br/temp/bx/out/store.parquet: ingested 2, duplicate 0 +measuring benchmarks on /home/ev-br/temp/bx/pandas (round 3, slot 7, env=pandas-3.1.1) +precision: 2 rounds x 5 repeat (config: /home/ev-br/temp/bx/benchx.conf.json) +asv: skipped module benchmarks.io.excel: ModuleNotFoundError: No module named 'odf' +asv: skipped module benchmarks.io.sql: ModuleNotFoundError: No module named 'sqlalchemy' +asv: skipped module benchmarks.plotting: ModuleNotFoundError: No module named 'matplotlib' +asv: skipped module benchmarks.sparse: ModuleNotFoundError: No module named 'scipy' +asv: skipped module benchmarks.timeseries: ModuleNotFoundError: No module named 'pandas.tseries.converter' +caveats: setup-per-call-unbatched +case median mean ± sd min .. max n status +---------------------------------------- -------- ------------------- -------------------- -- ------- +strings.Methods.time_lower [dtype='str'] 112.2 us 114.8 us ± 6.302 us 108.7 us .. 128.8 us 10 success + +2 result(s) -> out/pandas-asv (order sha256:de05e69a1731) +run-key: pandas-asv +/home/ev-br/temp/bx/out/store.parquet: ingested 2, duplicate 0 ``` -### 4. Compare +The output is a little verbose, mainly because we match the `asv`'s own output it emits +on missing modules (scipy, sqlalchemy etc). + +One output worth noting is `caveats: setup-per-call-unbatched`. The origin is that +the `Methods` class has a `setup` method, so, as in `asv_runner >= 0.3.0`, every +timed call sees fresh state: one call per loop, setup re-run between calls outside the timer. +For a ~100 µs call that timing includes some timer overhead, and the result is flagged. A +benchmark whose calls leave the set-up state intact can declare `setup_scope = "sample"`. +See [asv#1613](https://github.com/airspeed-velocity/asv/issues/1613) for details. + + +## Compare -The sides are told apart by the `env` label, and the two `grep` lines fail the -example if the comparison was refused, or if it does not name `deps.pandas` as the difference: +The caller loop above stored the information from individual runs into the _local store_ +under the `pandas-asv` run key. To run the comparison, we use `bx compare` and give it +enough information to specify the intent: +- all runs were stored under the `pandas-asv` run-key, `--run-key pandas-asv`; +- the comparison profile is `environments`; +- the sides are told apart by the `env` label; +- the `--baseline` value is one of the two labels. ```sh -$ bx compare --run pandas-asv --profile environments --label env --baseline pandas-2.3.3 | tee out/compare.txt -$ grep -q 'differs:.*deps\.pandas' out/compare.txt -$ ! grep -q 'failed invariants' out/compare.txt +$ bx compare --run pandas-asv --profile environments --label env --baseline pandas-2.3.3 ``` ```text -run pandas-asv profile environments baseline pandas-2.3.3 contender pandas-3.1.1 +run-key pandas-asv profile environments baseline pandas-2.3.3 contender pandas-3.1.1 differs: coordinates.environment.system.deps.pandas, coordinates.environment.system.deps.sha256 - caveats: baseline: setup-per-call-unbatched, contender: setup-per-call-unbatched + caveats: baseline: setup-per-call-unbatched + contender: setup-per-call-unbatched IMPROVED (1) - strings.Methods.time_lower wall-time effect -85.40% noise 1.76% rounds=4 + strings.Methods.time_lower [dtype='str'] wall-time effect -86.87% noise 0.05% rounds=4 +``` + +While the exact numbers may vary a bit, `effect` is the `effect` is the contender against +the baseline, averaged over the rounds' paired medians: `-86.87%` means pandas 3.1.1 takes +about `13%` of the time pandas 2.3.3 does, so about *7x faster*, well beyond the round-to-round `noise`. + +To additionally see `before` and `after` timings, adding `--tables` argument to `bx compare` call +prints + +``` +| Change | Before [pandas-2.3.3] | After [pandas-3.1.1] | Ratio | Noise | Verdict | Benchmark (Parameter) | +|----------|-------------------------|------------------------|---------|---------|-----------|-----------------------------------| +| - | 865±6μs | 113±2μs | 0.13 | 0.05% | improved | strings.Methods.time_lower('str') | ``` -(The numbers vary from run to run.) `effect` is the contender against the baseline, averaged -over the rounds' paired medians: `-85.40%` means pandas 3.1.1 takes about 15% of the time -pandas 2.3.3 does, so about 7x faster, well beyond the round-to-round `noise`. `differs` -names the environment facts that tell the sides apart: `deps.pandas` is the version the -collector printed, and `deps.sha256` is the hash of the collector's whole output, which -changes whenever any of its facts do. Here numpy and pyarrow are the same on both sides, so -pandas is the one difference. -### 5. List the series +The `differs` line names the environment facts that tell the sides apart: `deps.pandas` is the +pandas' version the _context collector_ printed, and `deps.sha256` is the hash of the collector's whole output, which +changes whenever any of its facts do. See below for details about the _context collectors_. + + +## Context collectors and environment facts + +*Context collectors* are the `benchx` way to collect *environment facts* which tell the sides of the comparison apart. +In this example, we compare the two virtual environmens which differ by the pandas version, which the collector records. + +In this example, the collector is defined in the +[configuration file, `benchx.conf.json`](https://github.com/benchx-dev/benchx/tree/main/examples/pandas-asv), which contains + +```json + "collectors": { + "deps": { + "command": ["python", "{root}/describe_env.py"] + } + } +``` + +and the `describe_env.py` script is + +```python +print(json.dumps({"summary": {"pandas": pandas.__version__, "numpy": numpy.__version__, + "pyarrow": pyarrow.__version__}}, sort_keys=True)) +``` + +`benchx` runs the collector script once per call, and records its output. This is where +the `coordinates.environment.system.deps.pandas` entry comes from that `bx compare` prints +in its `differs` section (the versions of `numpy` and `pyarrow` are the same in both +environments, thus `bx compare` does not report them). + +To check the environment facts the collector produced, you can either query the store, +or look in the log file: -One per environment, because the collected pandas version is part of -a series' identity. Every point carries the suite's revision (pandas `v3.1.1`), whichever -pandas it ran under: the target is the checkout the benchmarks come from, and what varies is -the environment, recorded by the collector. + +```sh +$ grep "benchx.collector" out/pandas-asv/bx.log | tail -n 6 +``` + +```text +2026-12-03T12:36:39.844Z 2185673 benchx.collectors DEBUG collector deps: python /home/ev-br/temp/bx/describe_env.py (in /home/ev-br/temp/bx/pandas, limit 60 s) +2026-12-03T12:36:40.154Z 2185673 benchx.collectors DEBUG collector deps: exit 0 in 0.3 s +2026-12-03T12:36:40.154Z 2185673 benchx.collectors DEBUG collector deps: stdout, 1 lines +2026-12-03T12:36:40.154Z 2185673 benchx.collectors DEBUG collector deps: stdout| {"summary": {"numpy": "2.5.5", "pandas": "3.1.1", "pyarrow": "26.0.1"}} +2026-12-03T12:36:40.155Z 2185673 benchx.collectors DEBUG collector deps: facts in /home/ev-br/temp/bx/out/pandas-asv/artifacts/slot-7/collector-deps.json +2026-12-03T12:36:40.155Z 2185673 benchx.collectors INFO collector 1/1 deps: ok, 0.3 s +``` + +Since the pandas version is recorded by the context collector, it becomes a part of the +series's identify---thus what we have is *two* series, one for each pandas version, +and this is exactly what enables the comparison: ```sh $ bx series --quantity wall-time ``` +```text +e89d8e4c550e pandas strings.Methods.time_lower wall-time [s] est=benchx/median/v1 +0a3a5ab6f525 pandas strings.Methods.time_lower wall-time [s] est=benchx/median/v1 +``` + + ## How it is configured -`benchx.conf.json` is found by walking up from the working directory, so `bx` reads it when run -from here: +The source of this example + +[`benchx.conf.json`](https://github.com/benchx-dev/benchx/blob/main/examples/pandas-asv/benchx.conf.json) is +found by walking up from the working directory, so `bx` reads it when run from here: - `adapter`: the harness (`asv`) and its precision, in pyperf's terms: 2 processes (asv's rounds) × 5 values (asv's repeat), 1 warmup, loops calibrated. Flags such as `--processes`, @@ -139,29 +350,8 @@ from here: That lands in each result's `environment.system.deps`, which is how the `environments` comparison knows what differs between the sides. - `paths`: the store and the results go in `out/`, so `bx series` shows this run only. - `$BENCHX_HOME` would relocate the store over this setting: do not set it. Each result also records the installed project's version (`provenance.info.asv.installed`) and asv's hash of the benchmark's code (`protocol.asv.benchmark_version`), so editing the benchmark starts a new series. -## Caveats - -- **`setup-per-call-unbatched`.** `Methods` has a `setup`, so, as in asv_runner >= 0.3.0, every - timed call sees fresh state: one call per loop, setup re-run between calls outside the timer. - For a ~100 µs call that timing includes some timer overhead, and the result is flagged. A - benchmark whose calls leave the set-up state intact can declare `setup_scope = "sample"`. -- **Memory benchmarks** (`peakmem_*`, `mem_*`) and other non-`time_*` types are listed and - skipped. -- **Unstable boot time.** pyperf's `boot_time` metadata is part of `environment.system`, which - the `environments` profile uses to tell sides apart. On hosts where the kernel's boot time - drifts (seen on WSL2), calls with the same label can then become separate sides, and the - comparison fails the `two-sides` invariant. This is a benchx issue, not specific to asv. - -## What is in this directory - -| File | Role | -|---|---| -| `README.md` | this walk-through, which is also the script: it is what the example runs | -| `benchx.conf.json` | the project file: the adapter and its precision, the `deps` collector, the paths | -| `describe_env.py` | the collector: prints the pandas, numpy and pyarrow this Python imports | From 5bfb002133175e2943e286372632c67884c17910 Mon Sep 17 00:00:00 2001 From: ev-br's Claude Code Agent Date: Fri, 27 Nov 2026 19:06:25 +0000 Subject: [PATCH 3/5] WIP: initial conversion of the pandas-asv example --- .github/workflows/docs.yml | 1 + docs/examples.md | 4 +- examples/pandas-asv/.gitignore | 4 + examples/pandas-asv/README.md | 167 +++++++++++++++++++++++++++ examples/pandas-asv/benchx.conf.json | 17 +++ examples/pandas-asv/describe_env.py | 16 +++ 6 files changed, 207 insertions(+), 2 deletions(-) create mode 100644 examples/pandas-asv/.gitignore create mode 100644 examples/pandas-asv/README.md create mode 100644 examples/pandas-asv/benchx.conf.json create mode 100644 examples/pandas-asv/describe_env.py diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index 1a65d3b..dfb7a7e 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -51,6 +51,7 @@ jobs: - example: pyperf-suite - example: matmul-params requires: numpy torch --index-url https://download.pytorch.org/whl/cpu + - example: pandas-asv env: EXAMPLE: ${{ matrix.example }} steps: diff --git a/docs/examples.md b/docs/examples.md index 6fff171..c163b12 100644 --- a/docs/examples.md +++ b/docs/examples.md @@ -39,6 +39,8 @@ in this repository. `bx bench`, the local store, and `bx series` / `bx history`. - [`matmul-params`](examples/matmul-params.md) — one benchmark function with several parameter combinations (sizes, numpy and torch), and a numpy-vs-torch comparison with `bx compare`. +- [`pandas-asv`](examples/pandas-asv.md) -- cross-environment comparison run of a specific benchmark + from the pandas ASV suite, under two pandas versions. Also shows how to run existing ASV benchmarks. ## Additional, cookbook-style examples @@ -49,8 +51,6 @@ Standalone, runnable examples of local usage live in a separate repository, environments ([UC-04](use-cases/UC-04-cross-env.md)). - `examples/numpy-spin` -- NumPy built with `spin` and a target provider: a benchmark tracked over a series of commits, and one varied by an environment variable. -- `examples/pandas-asv` -- cross-environment comparison run of a specific benchmark - from the pandas ASV suite. Also shows how to run existing ASV benchmarks. - `examples/arrow/demo/run.sh` — CMake + Google Benchmark walkthrough covering comparison profiles on a small C++ suite. - `examples/arrow/archery-local` — target provider walkthrough diff --git a/examples/pandas-asv/.gitignore b/examples/pandas-asv/.gitignore new file mode 100644 index 0000000..603dcac --- /dev/null +++ b/examples/pandas-asv/.gitignore @@ -0,0 +1,4 @@ +.venv-*/ +out/ +pandas/ +__pycache__/ diff --git a/examples/pandas-asv/README.md b/examples/pandas-asv/README.md new file mode 100644 index 0000000..cd5eb13 --- /dev/null +++ b/examples/pandas-asv/README.md @@ -0,0 +1,167 @@ +# pandas-asv: one pandas asv benchmark, two pandas versions + +One benchmark from pandas' own [asv](https://asv.readthedocs.io) suite, run unchanged by +`bx bench PATH --adapter asv` under two pandas versions, each in its own virtual environment, +alternated round by round, then compared. The asv adapter reads asv's benchmark format as a +language (discovery, `params`, `setup`, `setup_cache`, asv's benchmark version hash) and times it +with pyperf: neither asv nor asv_runner is installed. + +The suite is pandas' `asv_bench/` at one tag (`v3.1.1`), the same for both sides; only the +installed pandas differs. That is +[UC-04](https://github.com/benchx-dev/benchx/blob/main/docs/use-cases/UC-04-cross-env.md), +"fixed branch, comparing environments", driven the same way as `examples/numpy-venvs`. + +The case is `strings.Methods.time_lower('str')`: one parameter combination of one benchmark. +`dtype="str"` is object dtype in pandas 2.x and the pyarrow-backed string dtype from pandas 3.0, +so the two sides are expected to differ. + +## Run it + +You need [`uv`](https://docs.astral.sh/uv/), git, and network access the first time. Then run the +steps below from this directory. A run takes under a minute after the venvs are cached. + +Everything the steps create is in `pandas/`, `.venv-a`, `.venv-b` and `out/`, all git-ignored. +Start by removing what an earlier run left: + +```sh +$ rm -rf pandas .venv-a .venv-b out +``` + +benchx itself runs only inside the two venvs, and step 2 installs it there, from this checkout +(`../..`). Outside a checkout, install `benchx` from PyPI there instead. + +## What it does + +### 1. Fetch the suite + +A shallow, sparse clone of pandas at `v3.1.1`, with only `asv_bench/` +checked out (a few MB). Nothing is built: the benchmarks import the pandas installed in each +venv, and each case runs from a scratch directory, so the unbuilt checkout cannot shadow it. + +```sh +$ git -c advice.detachedHead=false clone -q --depth 1 --branch v3.1.1 --filter=blob:none --sparse https://github.com/pandas-dev/pandas.git pandas +$ git -C pandas sparse-checkout set asv_bench +$ git -C pandas rev-parse --short HEAD +``` + +### 2. Prepare two venvs + +`.venv-a` with pandas 2.3.3 and `.venv-b` with pandas 3.1.1, each +with pyarrow, pyperf and benchx. benchx builds nothing: the user prepares both environments. + +```sh +$ uv venv -q --python 3.12 .venv-a +$ uv pip install -q --python .venv-a/bin/python pandas==2.3.3 pyarrow pyperf -e ../.. +$ uv venv -q --python 3.12 .venv-b +$ uv pip install -q --python .venv-b/bin/python pandas==3.1.1 pyarrow pyperf -e ../.. +``` + +### 3. Run the caller's loop + +For each of the 4 rounds (the fewest that give a verdict), one call +per side, in its venv, with one slot per call: + +```sh +slot=0 +for round in 0 1 2 3; do + for side in a:2.3.3 b:3.1.1; do + . ".venv-${side%:*}/bin/activate" + bx bench pandas/asv_bench --adapter asv "strings.Methods.time_lower('str')" \ + --run-key pandas-asv --label "env=pandas-${side#*:}" \ + --round "$round" --slot "$slot" --out out/pandas-asv + slot=$((slot + 1)) + done +done +``` + +`pandas/asv_bench` holds `asv.conf.json`, whose `benchmark_dir` is the suite; its checkout +is the target. The exact case name selects one parameter combination; `--filter REGEX` +(asv's `--bench`) would select by pattern instead. Modules the venv cannot import (no +matplotlib, scipy, ...) are listed on stderr and skipped. Each call prints a table, one for +each of the 8 calls: + +```text +case median mean ± sd min .. max n status +---------------------------------------- -------- ------------------- -------------------- -- ----------------------------------- +strings.Methods.time_lower [dtype='str'] 890.2 us 937.6 us ± 122.9 us 835.2 us .. 1.202 ms 10 success [setup-per-call-unbatched] +``` + +### 4. Compare + +The sides are told apart by the `env` label, and the two `grep` lines fail the +example if the comparison was refused, or if it does not name `deps.pandas` as the difference: + +```sh +$ bx compare --run pandas-asv --profile environments --label env --baseline pandas-2.3.3 | tee out/compare.txt +$ grep -q 'differs:.*deps\.pandas' out/compare.txt +$ ! grep -q 'failed invariants' out/compare.txt +``` + +```text +run pandas-asv profile environments baseline pandas-2.3.3 contender pandas-3.1.1 + differs: coordinates.environment.system.deps.pandas, coordinates.environment.system.deps.sha256 + caveats: baseline: setup-per-call-unbatched, contender: setup-per-call-unbatched + +IMPROVED (1) + strings.Methods.time_lower wall-time effect -85.40% noise 1.76% rounds=4 +``` + +(The numbers vary from run to run.) `effect` is the contender against the baseline, averaged +over the rounds' paired medians: `-85.40%` means pandas 3.1.1 takes about 15% of the time +pandas 2.3.3 does, so about 7x faster, well beyond the round-to-round `noise`. `differs` +names the environment facts that tell the sides apart: `deps.pandas` is the version the +collector printed, and `deps.sha256` is the hash of the collector's whole output, which +changes whenever any of its facts do. Here numpy and pyarrow are the same on both sides, so +pandas is the one difference. + +### 5. List the series + +One per environment, because the collected pandas version is part of +a series' identity. Every point carries the suite's revision (pandas `v3.1.1`), whichever +pandas it ran under: the target is the checkout the benchmarks come from, and what varies is +the environment, recorded by the collector. + +```sh +$ bx series --quantity wall-time +``` + +## How it is configured + +`benchx.conf.json` is found by walking up from the working directory, so `bx` reads it when run +from here: + +- `adapter`: the harness (`asv`) and its precision, in pyperf's terms: 2 processes (asv's + rounds) × 5 values (asv's repeat), 1 warmup, loops calibrated. Flags such as `--processes`, + `--values`, `--min-time` and `--loops` override them per call. What neither gives comes from + each benchmark's own `repeat`, `number`, `sample_time` and `warmup_time`. +- `collectors.deps`: `describe_env.py`, a **context collector**. benchx runs it once per call, + in the environment the call runs in, and it prints the pandas, numpy and pyarrow it imports. + That lands in each result's `environment.system.deps`, which is how the `environments` + comparison knows what differs between the sides. +- `paths`: the store and the results go in `out/`, so `bx series` shows this run only. + `$BENCHX_HOME` would relocate the store over this setting: do not set it. + +Each result also records the installed project's version (`provenance.info.asv.installed`) and +asv's hash of the benchmark's code (`protocol.asv.benchmark_version`), so editing the benchmark +starts a new series. + +## Caveats + +- **`setup-per-call-unbatched`.** `Methods` has a `setup`, so, as in asv_runner >= 0.3.0, every + timed call sees fresh state: one call per loop, setup re-run between calls outside the timer. + For a ~100 µs call that timing includes some timer overhead, and the result is flagged. A + benchmark whose calls leave the set-up state intact can declare `setup_scope = "sample"`. +- **Memory benchmarks** (`peakmem_*`, `mem_*`) and other non-`time_*` types are listed and + skipped. +- **Unstable boot time.** pyperf's `boot_time` metadata is part of `environment.system`, which + the `environments` profile uses to tell sides apart. On hosts where the kernel's boot time + drifts (seen on WSL2), calls with the same label can then become separate sides, and the + comparison fails the `two-sides` invariant. This is a benchx issue, not specific to asv. + +## What is in this directory + +| File | Role | +|---|---| +| `README.md` | this walk-through, which is also the script: it is what the example runs | +| `benchx.conf.json` | the project file: the adapter and its precision, the `deps` collector, the paths | +| `describe_env.py` | the collector: prints the pandas, numpy and pyarrow this Python imports | diff --git a/examples/pandas-asv/benchx.conf.json b/examples/pandas-asv/benchx.conf.json new file mode 100644 index 0000000..ba18fdf --- /dev/null +++ b/examples/pandas-asv/benchx.conf.json @@ -0,0 +1,17 @@ +{ + "schema_version": "benchx/config/0.1.0", + "project": "pandas", + "adapter": { + "name": "asv", + "precision": { + "repetitions": { "mode": "fixed", "levels": [{ "unit": "process", "n": 2 }, { "unit": "value", "n": 5 }] }, + "warmup": { "mode": "count", "n_warmup": 1 } + } + }, + "collectors": { + "deps": { + "command": ["python", "{root}/describe_env.py"] + } + }, + "paths": { "store": "out/store.parquet", "results": "out" } +} diff --git a/examples/pandas-asv/describe_env.py b/examples/pandas-asv/describe_env.py new file mode 100644 index 0000000..2650951 --- /dev/null +++ b/examples/pandas-asv/describe_env.py @@ -0,0 +1,16 @@ +"""The collector: print the pandas this Python imports, and the libraries that decide how +fast it is. + +benchx.conf.json runs it once per call, in the environment the call runs in, so the two sides +can only differ here if their environments do. It prints the same text for the same +environment: no paths, no timestamps. +""" + +import json + +import numpy +import pandas +import pyarrow + +print(json.dumps({"summary": {"pandas": pandas.__version__, "numpy": numpy.__version__, + "pyarrow": pyarrow.__version__}}, sort_keys=True)) From b0bdf4f5a956e06c8f188fd200848526fb4e7cb9 Mon Sep 17 00:00:00 2001 From: ev-br's Claude Code Agent Date: Thu, 3 Dec 2026 10:41:37 +0000 Subject: [PATCH 4/5] ENH: log a context collector's stdout at DEBUG On success the stdout is the collector's facts. It was kept only in the collector-output artifact; now the log has it too (the last 40 lines, as for stderr). A failed collector still logs its stdout at WARNING. Co-Authored-By: Claude Sonnet 5.5 --- src/benchx/collectors.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/benchx/collectors.py b/src/benchx/collectors.py index 2d448e3..07badcb 100644 --- a/src/benchx/collectors.py +++ b/src/benchx/collectors.py @@ -84,8 +84,7 @@ def _collect(spec, cwd, env) -> tuple[dict | None, str | None]: ) failed = status is None or status != 0 log.harness_output(logger, f"collector {name}", "stderr", stderr, failed=failed) - if failed: # on success stdout is the facts, which are kept as the collector-output artifact - log.harness_output(logger, f"collector {name}", "stdout", stdout, failed=True) + log.harness_output(logger, f"collector {name}", "stdout", stdout, failed=failed) # on success: the facts if status is None: return None, f"timed out after {limit:g} s" if status != 0: @@ -120,10 +119,11 @@ def run_all(specs, *, declared, cwd, env, artifacts_dir, taken=()) -> Collected: "collector %s failed: %s", name, why ) # even when it only warns: the reason is lost otherwise else: - logger.info("collector %d/%d %s: ok, %.1f s", number, len(specs), name, took) digest = core.sha256_hex(core.canonical(facts)) path = Path(artifacts_dir) / f"collector-{name}.json" path.write_bytes(core.pretty(facts)) + logger.debug("collector %s: facts in %s", name, path.resolve()) + logger.info("collector %d/%d %s: ok, %.1f s", number, len(specs), name, took) out.artifacts.append(("collector-output", "application/json", path)) summary = facts.get("summary") if isinstance(facts.get("summary"), dict) else {} out.system[name] = {**summary, "sha256": digest} From 6f26a52c029a59f63eb4909de0c4e278837a547d Mon Sep 17 00:00:00 2001 From: Evgeni Burovski Date: Fri, 4 Dec 2026 09:25:09 +0100 Subject: [PATCH 5/5] DOC: fix rendering glitches --- docs/examples.md | 12 ------------ examples/matmul-params/README.md | 3 +-- examples/pandas-asv/README.md | 6 ++++-- 3 files changed, 5 insertions(+), 16 deletions(-) diff --git a/docs/examples.md b/docs/examples.md index a86cf91..86b2336 100644 --- a/docs/examples.md +++ b/docs/examples.md @@ -35,14 +35,6 @@ so that core `benchx` remains cloud-free and CI-vendor-neutral: The sources of these examples live in [`examples/`](https://github.com/benchx-dev/benchx/tree/main/examples) in this repository. -<<<<<<< HEAD -- [`pyperf-suite`](examples/pyperf-suite.md) -- timing a suite of Python functions with - `bx bench`, the local store, and `bx series` / `bx history`. -- [`matmul-params`](examples/matmul-params.md) — one benchmark function with several parameter - combinations (sizes, numpy and torch), and a numpy-vs-torch comparison with `bx compare`. -- [`pandas-asv`](examples/pandas-asv.md) -- cross-environment comparison run of a specific benchmark - from the pandas ASV suite, under two pandas versions. Also shows how to run existing ASV benchmarks. -======= - [`pyperf-suite`](examples/pyperf-suite.md) Demonstrates `benchx` basics: timing a suite of Python functions with `bx bench`, the local store, and `bx series` / `bx history`. - [`matmul-params`](examples/matmul-params.md) @@ -52,7 +44,6 @@ in this repository. - [`pandas-asv`](examples/pandas-asv.md) Demonstrates a *cross-environment* comparison run of a specific benchmark from the pandas ASV suite, under two pandas versions. Also shows how to run existing ASV benchmarks. ->>>>>>> origin/exec_example_pandas_asv_2 ## Additional, cookbook-style examples @@ -61,11 +52,8 @@ Standalone, runnable examples of local usage live in a separate repository, - `examples/numpy-venvs` — cross-environment comparison across two virtual environments ([UC-04](use-cases/UC-04-cross-env.md)). -<<<<<<< HEAD - `examples/numpy-spin` -- NumPy built with `spin` and a target provider: a benchmark tracked over a series of commits, and one varied by an environment variable. -======= ->>>>>>> origin/exec_example_pandas_asv_2 - `examples/arrow/demo/run.sh` — CMake + Google Benchmark walkthrough covering comparison profiles on a small C++ suite. - `examples/arrow/archery-local` — target provider walkthrough diff --git a/examples/matmul-params/README.md b/examples/matmul-params/README.md index 019af62..16ee1ff 100644 --- a/examples/matmul-params/README.md +++ b/examples/matmul-params/README.md @@ -315,5 +315,4 @@ For the *variants* comparison it is indeed unnecessary. However, `benchx` suppor `revisions` (where you run comparisons across the history of a project) and `environments` (where you hand `bx compare` two prepared virtual environments). These kinds of tasks involve building the project or activating environments---and `benchx` does not do either. This is where the read mode comparisons come in handy. See the -[`pandas-asv` worked example](https://github.com/benchx-dev/benchx_examples/tree/main/examples/pandas-asv) for an -end-to-end demo. +[`pandas-asv` worked example](https://benchx.dev/examples/pandas-asv/) for an end-to-end demo. diff --git a/examples/pandas-asv/README.md b/examples/pandas-asv/README.md index 87a3f53..90d89cb 100644 --- a/examples/pandas-asv/README.md +++ b/examples/pandas-asv/README.md @@ -72,6 +72,7 @@ For each of the 4 rounds (the fewest that give a verdict), one call per side, in its venv, with one slot per call. Note the parameters to `bx bench` calls: + - `--adapter asv` tells `benchx` that the benchmarks are written in the `asv` format; - the `"strings.Methods.time_lower('str')"` argument selects a single benchmark; - `--run-key pandas-asv` groups all runs under the same _run key_: having the same @@ -237,6 +238,7 @@ See [asv#1613](https://github.com/airspeed-velocity/asv/issues/1613) for details The caller loop above stored the information from individual runs into the _local store_ under the `pandas-asv` run key. To run the comparison, we use `bx compare` and give it enough information to specify the intent: + - all runs were stored under the `pandas-asv` run-key, `--run-key pandas-asv`; - the comparison profile is `environments`; - the sides are told apart by the `env` label; @@ -256,7 +258,7 @@ IMPROVED (1) strings.Methods.time_lower [dtype='str'] wall-time effect -86.87% noise 0.05% rounds=4 ``` -While the exact numbers may vary a bit, `effect` is the `effect` is the contender against +While the exact numbers may vary a bit, `effect` is the contender against the baseline, averaged over the rounds' paired medians: `-86.87%` means pandas 3.1.1 takes about `13%` of the time pandas 2.3.3 does, so about *7x faster*, well beyond the round-to-round `noise`. @@ -293,7 +295,7 @@ In this example, the collector is defined in the and the `describe_env.py` script is -```python +``` print(json.dumps({"summary": {"pandas": pandas.__version__, "numpy": numpy.__version__, "pyarrow": pyarrow.__version__}}, sort_keys=True)) ```