#!/usr/bin/env python3
"""Throughput benchmark: csv.DictReader + json.dump (stdlib).

Run:
    ./venv/bin/python bench_python.py
"""
import csv
import json
import time
from pathlib import Path

HERE = Path(__file__).parent
SRC = HERE / "sample.csv"
DST = HERE / "out_python.ndjson"


def main() -> None:
    rows = 0
    t0 = time.perf_counter()
    with SRC.open("r", encoding="utf-8", newline="") as fin, DST.open("w", encoding="utf-8") as fout:
        reader = csv.DictReader(fin)
        for row in reader:
            json.dump(row, fout, ensure_ascii=False)
            fout.write("\n")
            rows += 1
    dt = time.perf_counter() - t0
    print(f"csv.DictReader + json.dump: {rows:,} rows in {dt:.2f}s = {rows / dt:,.0f} rows/s")


if __name__ == "__main__":
    main()
