Skip to content
Myr

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 file

Take 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 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# ///

Bump serde from 1.0.174 to 1.0.179dependabot[bot]before adoption0f91d0c

lines 8–9why, one step back
8
9import argparse

Sort importsDavid Peterbefore adoptionbc37eff

line 10why, one step back
10

Bump serde from 1.0.174 to 1.0.179dependabot[bot]before adoption0f91d0c

lines 11–12why, one step back
11import numpy as np
12

Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9

line 13why, one step back
13from plot_utils import METRICS, add_metric_argument, load_results

Add --time-unit option to 'advanced_statistics.py'David Peterbefore adoptionf78f482

line 14why, one step back
14

Bump serde from 1.0.174 to 1.0.179dependabot[bot]before adoption0f91d0c

line 15why, one step back
15

Make plotting scripts runnable with uvDavid Peterbefore adoptionce49529

lines 16–25why, one step back
16def 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 back
26

Make plotting scripts runnable with uvDavid Peterbefore adoptionce49529

lines 27–34why, one step back
27 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.001

Bump serde from 1.0.174 to 1.0.179dependabot[bot]before adoption0f91d0c

line 35why, one step back
35

Make plotting scripts runnable with uvDavid Peterbefore adoptionce49529

lines 36–38why, one step back
36 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 back
39

Make plotting scripts runnable with uvDavid Peterbefore adoptionce49529

lines 40–43why, one step back
40 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 back
44

Make plotting scripts runnable with uvDavid Peterbefore adoptionce49529

line 45why, one step back
45 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 back
46

Make plotting scripts runnable with uvDavid Peterbefore adoptionce49529

line 47why, one step back
47 iqr = p75 - p25

Bump serde from 1.0.174 to 1.0.179dependabot[bot]before adoption0f91d0c

line 48why, one step back
48

Make plotting scripts runnable with uvDavid Peterbefore adoptionce49529

lines 49–62why, one step back
49 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 back
63

Make plotting scripts runnable with uvDavid Peterbefore adoptionce49529

lines 64–66why, one step back
64
65if __name__ == "__main__":66 main()