dsi-bitstream 0.9.2

A Rust implementation of read/write bit streams supporting several types of instantaneous codes
Documentation
#!/usr/bin/env python3

#
# SPDX-FileCopyrightText: 2025 Sebastiano Vigna
#
# SPDX-License-Identifier: Apache-2.0 OR LGPL-2.1-or-later
#

"""Extracts comparative benchmark results from Criterion's JSON output.

Reads the Criterion output directory and produces TSV output
compatible with the plot_comp.py script.

Usage:
    python3 extract_comp_results.py [--target-dir DIR]

Output columns: code, op, dist, endian, cilower, mean, ciupper
(mean and 95% confidence interval bounds, in ns/op).
"""

import argparse
import sys
from extract_criterion import default_criterion_dir, get_comp_bench_results


def main():
    parser = argparse.ArgumentParser(
        description="Extract Criterion comparative results into TSV for plot_comp.py"
    )
    parser.add_argument(
        "--target-dir",
        default=None,
        help="Path to the Criterion output directory (default: $CARGO_TARGET_DIR/criterion or target/criterion)",
    )
    args = parser.parse_args()

    target_dir = args.target_dir or default_criterion_dir()
    results = get_comp_bench_results(target_dir)
    if not results:
        sys.exit(f"No comparative benchmark results found in: {target_dir}")

    print("code\top\tdist\tendian\tcilower\tmean\tciupper")

    # Divide by N to get per-operation nanoseconds
    n = 1_000_000  # matches common::N

    for r in sorted(results, key=lambda x: (x["code"], x["op"], x["dist"], x["endian"])):
        print(
            "{}\t{}\t{}\t{}\t{:7.4f}\t{:7.4f}\t{:7.4f}".format(
                r["code"],
                r["op"],
                r["dist"],
                r["endian"],
                r["cilower"] / n,
                r["mean_ns"] / n,
                r["ciupper"] / n,
            )
        )


if __name__ == "__main__":
    main()