Skip to content
Myr

plot_progression.py

This file

Path

scripts/plot_progression.py

95 lines · 2.5 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–9why, one step back
2# /// script
3# requires-python = ">=3.10"4# dependencies = [5# "pyqt6",6# "matplotlib",7# "numpy",8# ]9# ///

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

lines 10–16why, one step back
10
11"""This program shows `hyperfine` benchmark results in a sequential way12in order to debug possible background interference, caching effects,13thermal throttling and similar effects.14"""1516import argparse

Sort importsDavid Peterbefore adoptionbc37eff

line 17why, one step back
17

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

lines 18–20why, one step back
18import matplotlib.pyplot as plt
19import numpy as np20

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

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

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

line 22why, one step back
22

Support all exported metrics in plotting scripts (#981)David Peterbefore adoptionef86c83

lines 23–26why, one step back
23
24def moving_average(values, num_runs):25 values_padded = np.pad(26 values, (num_runs // 2, num_runs - 1 - num_runs // 2), mode="edge"

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

lines 27–28why, one step back
27 )
28 kernel = np.ones(num_runs) / num_runs

Support all exported metrics in plotting scripts (#981)David Peterbefore adoptionef86c83

line 29why, one step back
29 return np.convolve(values_padded, kernel, mode="valid")

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

lines 30–31why, one step back
30
31

Make plotting scripts runnable with uvDavid Peterbefore adoptionce49529

lines 32–49why, one step back
32def main():
33 parser = argparse.ArgumentParser(description=__doc__)34 add_metric_argument(parser)35 parser.add_argument("file", help="JSON file with benchmark results")36 parser.add_argument("--title", help="Plot Title")37 parser.add_argument("-o", "--output", help="Save image to the given filename.")38 parser.add_argument(39 "-w",40 "--moving-average-width",41 type=int,42 metavar="num_runs",43 help="Width of the moving-average window (default: N/5)",44 )45 parser.add_argument(46 "--no-moving-average",47 action="store_true",48 help="Do not show moving average curve",49 )

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

line 50why, one step back
50

Make plotting scripts runnable with uvDavid Peterbefore adoptionce49529

lines 51–53why, one step back
51 args = parser.parse_args()
52 metric, [results] = load_results(parser, [args.file], args.metric)53 metric_info = METRICS[metric]

Improve plot_progression.py scriptDavid Peterbefore adoptionc7be935

line 54why, one step back
54

Make plotting scripts runnable with uvDavid Peterbefore adoptionce49529

lines 55–60why, one step back
55 for result in results:
56 values = [57 m[metric]["value"] / metric_info.scale for m in result["measurements"]58 ]59 num = len(values)60 nums = range(num)

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

line 61why, one step back
61

Make plotting scripts runnable with uvDavid Peterbefore adoptionce49529

lines 62–64why, one step back
62 plt.scatter(x=nums, y=values, marker=".")
63 plt.ylim([0, None])64 plt.xlim([-1, num])

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

line 65why, one step back
65

Make plotting scripts runnable with uvDavid Peterbefore adoptionce49529

lines 66–71why, one step back
66 if not args.no_moving_average:
67 moving_average_width = (68 max(1, num // 5)69 if args.moving_average_width is None70 else args.moving_average_width71 )

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

line 72why, one step back
72

Make plotting scripts runnable with uvDavid Peterbefore adoptionce49529

lines 73–74why, one step back
73 average = moving_average(values, moving_average_width)
74 plt.plot(nums, average, "-")

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

line 75why, one step back
75

Make plotting scripts runnable with uvDavid Peterbefore adoptionce49529

lines 76–77why, one step back
76 if args.title:
77 plt.title(args.title)

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

line 78why, one step back
78

Make plotting scripts runnable with uvDavid Peterbefore adoptionce49529

lines 79–84why, one step back
79 legend = []
80 for result in results:81 legend.append(result.get("name", result["command"]))82 if not args.no_moving_average:83 legend.append("moving average")84 plt.legend(legend)

Improve plot_progression.py scriptDavid Peterbefore adoptionc7be935

line 85why, one step back
85

Make plotting scripts runnable with uvDavid Peterbefore adoptionce49529

line 86why, one step back
86 plt.ylabel(metric_info.axis_label)

Improve plot_progression.py scriptDavid Peterbefore adoptionc7be935

line 87why, one step back
87

Make plotting scripts runnable with uvDavid Peterbefore adoptionce49529

lines 88–91why, one step back
88 if args.output:
89 plt.savefig(args.output)90 else:91 plt.show()

Improve plot_progression.py scriptDavid Peterbefore adoptionc7be935

line 92why, one step back
92

Make plotting scripts runnable with uvDavid Peterbefore adoptionce49529

lines 93–95why, one step back
93
94if __name__ == "__main__":95 main()