Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
15 changes: 9 additions & 6 deletions docs/examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down
3 changes: 1 addition & 2 deletions examples/matmul-params/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
4 changes: 4 additions & 0 deletions examples/pandas-asv/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.venv-*/
out/
pandas/
__pycache__/
359 changes: 359 additions & 0 deletions examples/pandas-asv/README.md

Large diffs are not rendered by default.

17 changes: 17 additions & 0 deletions examples/pandas-asv/benchx.conf.json
Original file line number Diff line number Diff line change
@@ -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" }
}
16 changes: 16 additions & 0 deletions examples/pandas-asv/describe_env.py
Original file line number Diff line number Diff line change
@@ -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))
6 changes: 3 additions & 3 deletions src/benchx/collectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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}
Expand Down
Loading