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..86b2336 100644 --- a/docs/examples.md +++ b/docs/examples.md @@ -35,10 +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`. +- [`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 @@ -49,8 +54,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/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/.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..90d89cb --- /dev/null +++ b/examples/pandas-asv/README.md @@ -0,0 +1,359 @@ +# pandas-asv: one pandas asv benchmark, two pandas versions + +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". + +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. + +## 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: + +```sh +$ rm -rf pandas .venv-a .venv-b out +``` + +### 1. Fetch the suite + +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 +$ 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 + +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 +$ 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 ../.. +``` + +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. + +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 + 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 + slot=$((slot + 1)) + done +done +``` + +```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'] 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 +``` + +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 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 +``` + +```text +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 + +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 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 `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 + +``` +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: + + +```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 + +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`, + `--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. + +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. + 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)) 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}