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 fileTake 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 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 clap_complete from 4.2.0 to 4.2.1dependabot[bot]before adoptionab5ae5f
lines 8–9why, one step back89import argparseSort importsDavid Peterbefore adoptionbc37eff
line 10why, one step back10Bump clap_complete from 4.2.0 to 4.2.1dependabot[bot]before adoptionab5ae5f
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 clap_complete from 4.2.0 to 4.2.1dependabot[bot]before adoptionab5ae5f
lines 15–16why, one step back15parser = 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 back17add_metric_argument(parser)Add --time-unit option to 'advanced_statistics.py'David Peterbefore adoptionf78f482
lines 18–19why, one step back18parser.add_argument(19 "--time-unit",Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
line 20why, one step back20 help="Display unit for time metrics (default: second).",Add --time-unit option to 'advanced_statistics.py'David Peterbefore adoptionf78f482
lines 21–22why, one step back21 choices=["second", "millisecond"],22)Bump clap_complete from 4.2.0 to 4.2.1dependabot[bot]before adoptionab5ae5f
lines 23–24why, one step back23args = parser.parse_args()24Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
lines 25–32why, one step back25metric, [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.001Add --time-unit option to 'advanced_statistics.py'David Peterbefore adoptionf78f482
line 33why, one step back33Bump clap_complete from 4.2.0 to 4.2.1dependabot[bot]before adoptionab5ae5f
line 34why, one step back34Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
lines 35–40why, one step back35def 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 back41for result in results:Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
lines 42–43why, one step back42 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 back44Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
line 45why, one step back45 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 back4647 iqr = p75 - p2548Merge pull request #790 from sharkdp/new-metricsDavid Peterbefore adoptionf26c015
lines 49–50why, one step back49 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 back51 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 back55 print()56 print(" percentiles:")Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
line 57why, one step back57 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 back58 print(Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
lines 59–60why, one step back59 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 back61 )Bump clap_complete from 4.2.0 to 4.2.1dependabot[bot]before adoptionab5ae5f
line 62why, one step back62 print()