Skip to content

Parse benchmark results

Use load_benchmark_json to extract only benchmatrix-tagged rows from a pytest-benchmark JSON file.

from benchmatrix import load_benchmark_json

rows = load_benchmark_json("benchmark.json")

Display a concise table:

from benchmatrix import display_benchmark_rows

display_benchmark_rows(rows)

Handle invalid or mixed files

pytest-benchmark JSON may contain rows that were not generated by benchmatrix. The parser keeps benchmatrix rows separate so unrelated benchmark data does not silently acquire benchmatrix semantics.

If parsing fails, treat the exception as a contract problem with the input file:

  • confirm the file came from pytest-benchmark JSON export;
  • confirm the benchmark was generated by benchmatrix;
  • preserve the original JSON as a fixture when adding parser tests.

Use result fixtures in tests

Representative JSON fixtures belong under tests/fixtures/benchmark_results/. Prefer fixtures when the JSON shape matters more than a small inline dictionary.