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 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–9why, one step back2# /// script3# 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 back1011"""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 argparseSort importsDavid Peterbefore adoptionbc37eff
line 17why, one step back17Bump serde from 1.0.174 to 1.0.179dependabot[bot]before adoption0f91d0c
lines 18–20why, one step back18import matplotlib.pyplot as plt19import numpy as np20Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
line 21why, one step back21from plot_utils import METRICS, add_metric_argument, load_resultsBump serde from 1.0.174 to 1.0.179dependabot[bot]before adoption0f91d0c
line 22why, one step back22Support all exported metrics in plotting scripts (#981)David Peterbefore adoptionef86c83
lines 23–26why, one step back2324def 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 back27 )28 kernel = np.ones(num_runs) / num_runsSupport all exported metrics in plotting scripts (#981)David Peterbefore adoptionef86c83
line 29why, one step back29 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 back3031Make plotting scripts runnable with uvDavid Peterbefore adoptionce49529
lines 32–49why, one step back32def 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 back50Make plotting scripts runnable with uvDavid Peterbefore adoptionce49529
lines 51–53why, one step back51 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 back54Make plotting scripts runnable with uvDavid Peterbefore adoptionce49529
lines 55–60why, one step back55 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 back61Make plotting scripts runnable with uvDavid Peterbefore adoptionce49529
lines 62–64why, one step back62 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 back65Make plotting scripts runnable with uvDavid Peterbefore adoptionce49529
lines 66–71why, one step back66 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 back72Make plotting scripts runnable with uvDavid Peterbefore adoptionce49529
lines 73–74why, one step back73 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 back75Make plotting scripts runnable with uvDavid Peterbefore adoptionce49529
lines 76–77why, one step back76 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 back78Make plotting scripts runnable with uvDavid Peterbefore adoptionce49529
lines 79–84why, one step back79 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 back85Make plotting scripts runnable with uvDavid Peterbefore adoptionce49529
line 86why, one step back86 plt.ylabel(metric_info.axis_label)Improve plot_progression.py scriptDavid Peterbefore adoptionc7be935
line 87why, one step back87Make plotting scripts runnable with uvDavid Peterbefore adoptionce49529
lines 88–91why, one step back88 if args.output:89 plt.savefig(args.output)90 else:91 plt.show()Improve plot_progression.py scriptDavid Peterbefore adoptionc7be935
line 92why, one step back92Make plotting scripts runnable with uvDavid Peterbefore adoptionce49529
lines 93–95why, one step back9394if __name__ == "__main__":95 main()