Skip to content
Myr

advanced_statistics.py

This file

Path

scripts/advanced_statistics.py

42 lines · 1.1 KiB · Python

Last changed by

Add PEP-723 inline metadataDavid Peterbefore adoptioncfae9cb

History of this file

Take it

The walk stopped after 200 commits: lines older than ec43213 point at it.

Fix clippy warningsDavid Peterbefore adoptionec43213

line 1why, one step back
1#!/usr/bin/env python

Add PEP-723 inline metadataDavid Peterbefore adoptioncfae9cb

lines 2–7why, one step back
2# /// script
3# requires-python = ">=3.10"4# dependencies = [5# "numpy",6# ]7# ///

Fix clippy warningsDavid Peterbefore adoptionec43213

lines 8–30why, one step back
8
9import argparse10import json11import numpy as np1213parser = argparse.ArgumentParser()14parser.add_argument("file", help="JSON file with benchmark results")15args = parser.parse_args()1617with open(args.file) as f:18 results = json.load(f)["results"]1920commands = [b["command"] for b in results]21times = [b["times"] for b in results]2223for command, ts in zip(commands, times):24 p05 = np.percentile(ts, 5)25 p25 = np.percentile(ts, 25)26 p75 = np.percentile(ts, 75)27 p95 = np.percentile(ts, 95)2829 iqr = p75 - p2530

Update formatting, use f-stringsDavid Peterbefore adoption65dd84f

lines 31–37why, one step back
31 print(f"Command '{command}'")
32 print(f" runs: {len(ts):8d}")33 print(f" mean: {np.mean(ts):8.3f} s")34 print(f" stddev: {np.std(ts, ddof=1):8.3f} s")35 print(f" median: {np.median(ts):8.3f} s")36 print(f" min: {np.min(ts):8.3f} s")37 print(f" max: {np.max(ts):8.3f} s")

Fix clippy warningsDavid Peterbefore adoptionec43213

lines 38–39why, one step back
38 print()
39 print(" percentiles:")

Update formatting, use f-stringsDavid Peterbefore adoption65dd84f

lines 40–41why, one step back
40 print(f" P_05 .. P_95: {p05:.3f} s .. {p95:.3f} s")
41 print(f" P_25 .. P_75: {p25:.3f} s .. {p75:.3f} s " f"(IQR = {iqr:.3f} s)")

Fix clippy warningsDavid Peterbefore adoptionec43213

line 42why, one step back
42 print()