advanced_statistics.py
This file
Path
scripts/advanced_statistics.py
66 lines · 2.0 KiB · Python
Last changed by
Make plotting scripts runnable with uvDavid Peterbefore adoptionce49529
History of this fileTake it
The walk stopped after 200 commits: lines older than 0f91d0c point at it.
Bump serde from 1.0.174 to 1.0.179dependabot[bot]before adoption0f91d0c
line 1why, one step back1#!/usr/bin/env pythonAdd PEP-723 inline metadataDavid Peterbefore adoptioncfae9cb
lines 2–7why, one step back2# /// script3# requires-python = ">=3.10"4# dependencies = [5# "numpy",6# ]7# ///Bump serde from 1.0.174 to 1.0.179dependabot[bot]before adoption0f91d0c
lines 8–9why, one step back89import argparseSort importsDavid Peterbefore adoptionbc37eff
line 10why, one step back10Bump serde from 1.0.174 to 1.0.179dependabot[bot]before adoption0f91d0c
lines 11–12why, one step back11import numpy as np12Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
line 13why, one step back13from plot_utils import METRICS, add_metric_argument, load_resultsAdd --time-unit option to 'advanced_statistics.py'David Peterbefore adoptionf78f482
line 14why, one step back14Bump serde from 1.0.174 to 1.0.179dependabot[bot]before adoption0f91d0c
line 15why, one step back15Make plotting scripts runnable with uvDavid Peterbefore adoptionce49529
lines 16–25why, one step back16def main():17 parser = argparse.ArgumentParser()18 parser.add_argument("file", help="JSON file with benchmark results")19 add_metric_argument(parser)20 parser.add_argument(21 "--time-unit",22 help="Display unit for time metrics (default: second).",23 choices=["second", "millisecond"],24 )25 args = parser.parse_args()Add --time-unit option to 'advanced_statistics.py'David Peterbefore adoptionf78f482
line 26why, one step back26Make plotting scripts runnable with uvDavid Peterbefore adoptionce49529
lines 27–34why, one step back27 metric, [results] = load_results(parser, [args.file], args.metric)28 description = METRICS[metric]29 unit, scale = description.unit, description.scale30 if args.time_unit is not None:31 if not metric.startswith("time_"):32 parser.error("--time-unit can only be used with a time metric")33 if args.time_unit == "millisecond":34 unit, scale = "ms", 0.001Bump serde from 1.0.174 to 1.0.179dependabot[bot]before adoption0f91d0c
line 35why, one step back35Make plotting scripts runnable with uvDavid Peterbefore adoptionce49529
lines 36–38why, one step back36 def format_value(value):37 suffix = f" {unit}" if unit else ""38 return f"{value:.3f}{suffix}"Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
line 39why, one step back39Make plotting scripts runnable with uvDavid Peterbefore adoptionce49529
lines 40–43why, one step back40 print(f"Metric: {description.label}\n")41 for result in results:42 summary = result["summary"][metric]43 values = [m[metric]["value"] / scale for m in result["measurements"]]Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
line 44why, one step back44Make plotting scripts runnable with uvDavid Peterbefore adoptionce49529
line 45why, one step back45 p05, p25, p75, p95 = np.percentile(values, [5, 25, 75, 95])Bump serde from 1.0.174 to 1.0.179dependabot[bot]before adoption0f91d0c
line 46why, one step back46Make plotting scripts runnable with uvDavid Peterbefore adoptionce49529
line 47why, one step back47 iqr = p75 - p25Bump serde from 1.0.174 to 1.0.179dependabot[bot]before adoption0f91d0c
line 48why, one step back48Make plotting scripts runnable with uvDavid Peterbefore adoptionce49529
lines 49–62why, one step back49 print(f"Command '{result.get('name', result['command'])}'")50 print(f" runs: {summary['count']:8d}")51 for statistic in ["mean", "stddev", "median", "min", "max"]:52 value = summary[statistic]53 formatted = "N/A" if value is None else format_value(value / scale)54 print(f" {statistic + ':':<8}{formatted:>8}")55 print()56 print(" percentiles:")57 print(f" P_05 .. P_95: {format_value(p05)} .. {format_value(p95)}")58 print(59 f" P_25 .. P_75: {format_value(p25)} .. {format_value(p75)}"60 f" (IQR = {format_value(iqr)})"61 )62 print()Bump serde from 1.0.174 to 1.0.179dependabot[bot]before adoption0f91d0c
line 63why, one step back63Make plotting scripts runnable with uvDavid Peterbefore adoptionce49529
lines 64–66why, one step back6465if __name__ == "__main__":66 main()