Skip to content
Myr

advanced_statistics.py

This file

Path

scripts/advanced_statistics.py

62 lines · 1.8 KiB · Python

Last changed by

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

History of this file

Take it

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

Bump clap_complete from 4.2.0 to 4.2.1dependabot[bot]before adoptionab5ae5f

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 clap_complete from 4.2.0 to 4.2.1dependabot[bot]before adoptionab5ae5f

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

Sort importsDavid Peterbefore adoptionbc37eff

line 10why, one step back
10

Bump clap_complete from 4.2.0 to 4.2.1dependabot[bot]before adoptionab5ae5f

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 clap_complete from 4.2.0 to 4.2.1dependabot[bot]before adoptionab5ae5f

lines 15–16why, one step back
15parser = argparse.ArgumentParser()
16parser.add_argument("file", help="JSON file with benchmark results")

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

line 17why, one step back
17add_metric_argument(parser)

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

lines 18–19why, one step back
18parser.add_argument(
19 "--time-unit",

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

line 20why, one step back
20 help="Display unit for time metrics (default: second).",

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

lines 21–22why, one step back
21 choices=["second", "millisecond"],
22)

Bump clap_complete from 4.2.0 to 4.2.1dependabot[bot]before adoptionab5ae5f

lines 23–24why, one step back
23args = parser.parse_args()
24

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

lines 25–32why, one step back
25metric, [results] = load_results(parser, [args.file], args.metric)
26description = METRICS[metric]27unit, scale = description.unit, description.scale28if args.time_unit is not None:29 if not metric.startswith("time_"):30 parser.error("--time-unit can only be used with a time metric")31 if args.time_unit == "millisecond":32 unit, scale = "ms", 0.001

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

line 33why, one step back
33

Bump clap_complete from 4.2.0 to 4.2.1dependabot[bot]before adoptionab5ae5f

line 34why, one step back
34

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

lines 35–40why, one step back
35def format_value(value):
36 suffix = f" {unit}" if unit else ""37 return f"{value:.3f}{suffix}"383940print(f"Metric: {description.label}\n")

Merge pull request #790 from sharkdp/new-metricsDavid Peterbefore adoptionf26c015

line 41why, one step back
41for result in results:

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

lines 42–43why, one step back
42 summary = result["summary"][metric]
43 values = [m[metric]["value"] / scale for m in result["measurements"]]

Bump clap_complete from 4.2.0 to 4.2.1dependabot[bot]before adoptionab5ae5f

line 44why, one step back
44

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

line 45why, one step back
45 p05, p25, p75, p95 = np.percentile(values, [5, 25, 75, 95])

Bump clap_complete from 4.2.0 to 4.2.1dependabot[bot]before adoptionab5ae5f

lines 46–48why, one step back
46
47 iqr = p75 - p2548

Merge pull request #790 from sharkdp/new-metricsDavid Peterbefore adoptionf26c015

lines 49–50why, one step back
49 print(f"Command '{result.get('name', result['command'])}'")
50 print(f" runs: {summary['count']:8d}")

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

lines 51–54why, one step back
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}")

Bump clap_complete from 4.2.0 to 4.2.1dependabot[bot]before adoptionab5ae5f

lines 55–56why, one step back
55 print()
56 print(" percentiles:")

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

line 57why, one step back
57 print(f" P_05 .. P_95: {format_value(p05)} .. {format_value(p95)}")

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

line 58why, one step back
58 print(

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

lines 59–60why, one step back
59 f" P_25 .. P_75: {format_value(p25)} .. {format_value(p75)}"
60 f" (IQR = {format_value(iqr)})"

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

line 61why, one step back
61 )

Bump clap_complete from 4.2.0 to 4.2.1dependabot[bot]before adoptionab5ae5f

line 62why, one step back
62 print()