"""The stopwatch test: run the Experiment 1 loop 5 times at the same size.

Do the times match? Do the step counts? Times depend on the machine
and what else it is doing; step counts do not.
"""
from common import median, save, time_runs
from exp1_add_up import add_up_loop

N = 10_000_000


def main():
    results, times = time_runs(add_up_loop, N)
    _, steps = results
    print(f"Loop at n = {N:,}, {len(times)} runs")
    runs = []
    for run, ms in enumerate(times, start=1):
        print(f"run {run}: {ms:10.1f} ms | {steps:,} steps")
        runs.append({"run": run, "ms": round(ms, 1), "steps": steps})
    print(f"median {median(times):.1f} ms, spread {min(times):.1f} to {max(times):.1f} ms")
    save("bonus", {"n": N, "runs": runs, "median_ms": round(median(times), 1)})


if __name__ == "__main__":
    main()
