"""Reproduce the indexing benchmarks reported in the article. Usage: python benchmark.py --repos repos.txt --runs 5 --out benchmark-results.csv """ from __future__ import annotations import argparse import csv import statistics import time from pathlib import Path def time_walk(root: Path, workers: int | None) -> float: """Return wall-clock seconds for one full walk of `root`.""" start = time.perf_counter() # Placeholder: call the real walker under test here. list(root.rglob("*")) return time.perf_counter() - start def main() -> None: parser = argparse.ArgumentParser(description=__doc__) parser.add_argument("--repos", type=Path, required=True) parser.add_argument("--runs", type=int, default=5) parser.add_argument("--out", type=Path, default=Path("benchmark-results.csv")) args = parser.parse_args() roots = [Path(line.strip()) for line in args.repos.read_text().splitlines() if line.strip()] with args.out.open("w", newline="", encoding="utf-8") as handle: writer = csv.writer(handle) writer.writerow(["repository", "config", "median_seconds", "runs"]) for root in roots: for label, workers in (("sequential", None), ("parallel", 8)): timings = [time_walk(root, workers) for _ in range(args.runs)] writer.writerow([root.name, label, round(statistics.median(timings), 3), args.runs]) print(f"{root.name:24} {label:10} {statistics.median(timings):.3f}s") if __name__ == "__main__": main()