This directory contains performance benchmarks for k-wave-python. These are not standard examples: they are intended to measure runtime and memory behavior and can become expensive as the grid size grows.
benchmark.py ports MATLAB k-Wave's benchmark.m. It runs kspaceFirstOrder on a sequence of 3D grids with increasing sizes, averages runtime over repeated runs, and saves partial results after each run.
The default benchmark uses:
- heterogeneous absorbing medium
- smoothed initial pressure ball source
- binary sensor mask built from 100 Cartesian points on a sphere
- 1000 time steps
- 3 averages per grid size
- grid sizes based on MATLAB's original scale arrays, starting at
32 x 32 x 32
By default, this can run for a long time and may stop once memory limits are reached.
Run a small smoke benchmark:
uv run benchmarks/benchmark.py --max-cases 1 --num-averages 1 --number-time-points 20Run the default CPU benchmark:
uv run benchmarks/benchmark.pyRun with single-precision arrays:
uv run benchmarks/benchmark.py --data-cast singleRun on the Python GPU backend:
uv run benchmarks/benchmark.py --device gpuChoose an output file:
uv run benchmarks/benchmark.py --output-path benchmark_data.jsonThe benchmark writes a JSON file containing:
comp_size: total grid points for each completed grid sizecomp_time: rolling average elapsed seconds for each grid sizeoptions: benchmark settings and environment metadataoutput_path: path to the JSON output fileerror_reached: whether the benchmark stopped after an exceptionerror_message: exception message, if anymem_usage: optional process peak memory estimate when--report-mem-usageis set
Partial results are saved after each run so completed timings are preserved if a later grid fails.