# Benchmarks

Timing comparison between **meshio++** (`meshioplusplus`, C++-accelerated) and
the original pure-Python **meshio**, on the formats both libraries support.

| File | Purpose |
|------|---------|
| [`01_benchmark.ipynb`](01_benchmark.ipynb) | Runs the benchmark, writes `results.csv`, and generates the plots. Committed **with outputs**. |
| `bench.py` | Harness: imports both libraries, times read/write per format (median of N runs, with warmup). |
| `inputs.py` | The two input meshes: the `example.msh` bracket geometry and a numpy-generated tetrahedral cube. |
| `results.csv` | Latest results (regenerated by the notebook). |
| `plots/` | Generated figures (also copied to `doc/public/benchmarks/`). |

The legacy pure-Python `meshio` is imported from source
(`/home/vicente/src/meshio_legacy/src`) via `sys.path` — it is pure Python, so
no build step is needed and it does not collide with `meshioplusplus`.

## Running

```sh
uv pip install --python ../.venv matplotlib jupyter nbconvert ipykernel
../.venv/bin/jupyter nbconvert --to notebook --execute --inplace 01_benchmark.ipynb
```

See [`doc/benchmarks.md`](../doc/benchmarks.md) for the write-up and the
interpretation (meshio++ wins big on text/ASCII formats; binary dumps already at
numpy speed in pure Python see little or no gain).

## Mesh-backend benchmark (pure C++)

`bench_backends.sh` compares the C++ **mesh backends** (MESHIO / NATIVE /
KRATOS) — no Python involved. The backend is a compile-time choice, so the
script configures one throwaway tree per backend under `build/bench-<backend>`
(`-DMESHIOPLUSPLUS_BUILD_BENCHMARKS=ON`, Python off), runs
`meshioplusplus_bench` (from `cpp/benchmark/bench_backends.cpp`) in each, and
collates `results_backends.csv`:

```sh
./bench_backends.sh        # default n=35 -> 257k tets
./bench_backends.sh 50     # bigger synthetic grid
```

Rows: `ingest` (uniform-API mesh construction), `traverse` (writer-side
accessor sweep), `to_modelpart` (KRATOS-only ModelPart materialization), and
`write`/`read` file round-trips per format. See the "Mesh-backend benchmarks"
section of [`doc/benchmarks.md`](../doc/benchmarks.md).
