Benchmark Utilities

Purpose

Benchmark Utilities address the need for streamlined loading, caching, and aggregation of benchmark data and test fixtures to support comprehensive performance testing of JSON serialization and deserialization libraries. This subtopic solves the problem of efficiently managing large JSON test inputs and benchmark results, enabling consistent, repeatable, and performance-optimized benchmark workflows. By abstracting fixture handling and result aggregation, it reduces duplication and complexity across serialization and deserialization benchmarks.

Functionality

The core functionalities provided by Benchmark Utilities include:

Together, these utilities form the backbone for the benchmark suite's data handling and reporting processes.

Key Workflow Example: Fixture Loading and Caching

@cache
def read_fixture(filename: str) -> bytes:
    path = Path(dirname, filename)
    if path.suffix == ".xz":
        contents = lzma.decompress(path.read_bytes())
    else:
        contents = path.read_bytes()
    return contents


@cache
def read_fixture_obj(filename: str) -> Any:
    return orjson.loads(read_fixture(filename))

Benchmark Data Aggregation and Visualization (Excerpt)

The `aggregate()` function loads benchmark JSON result files, extracting timing stats and correctness flags per library and test group. The `tab()` function formats this into Markdown tables and generates plots using seaborn and matplotlib.

def aggregate():
    # Load benchmark files and organize by group and library
    ...

def tab(obj):
    # Format tables and create barplots comparing library performances
    ...

This approach allows automated generation of detailed benchmark reports and visual summaries.

Relationship

Benchmark Utilities complement and enable the **Serialization Benchmarks** and **Deserialization Benchmarks** subtopics by providing shared infrastructure for fixture management and result processing. While serialization and deserialization benchmarks focus on measuring and validating performance of JSON operations, Benchmark Utilities abstract common tasks such as:

This subtopic is distinct because it exclusively focuses on utilities that support benchmark workflows rather than the benchmarks themselves or the core JSON processing logic. It ensures that the benchmarking ecosystem is maintainable, reproducible, and scalable.

Diagram

flowchart TD
    A[Start Benchmark Run] --> B[Load Fixture File]
    B --> C{Compressed?}
    C -->|Yes| D[Decompress Fixture]
    C -->|No| E[Read Raw Fixture Bytes]
    D --> F[Cache Fixture Bytes]
    E --> F
    F --> G[Parse Fixture to Object]
    G --> H[Cache Parsed Object]
    H --> I[Run Serialization / Deserialization Benchmark]
    I --> J[Write Benchmark Results as JSON]
    J --> K[Aggregate Benchmark Results]
    K --> L[Generate Tables and Graphs]
    L --> M[Output Benchmark Reports]

This flowchart illustrates the core process managed by Benchmark Utilities, from loading and caching fixtures, through running benchmarks, to aggregating and reporting results. It highlights critical caching steps that maximize efficiency and the transformation from raw benchmark data to insightful reports.