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")
n = 1_000_000
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()