plot_progression.py
This file
Path
scripts/plot_progression.py
94 lines · 2.4 KiB · Python
Last changed by
Support all exported metrics in plotting scripts (#981)David Peterbefore adoptionef86c83
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–9why, one step back2# /// script3# requires-python = ">=3.10"4# dependencies = [5# "pyqt6",6# "matplotlib",7# "numpy",8# ]9# ///Bump clap_complete from 4.2.0 to 4.2.1dependabot[bot]before adoptionab5ae5f
lines 10–17why, 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 argparse17import jsonSort importsDavid Peterbefore adoptionbc37eff
line 18why, one step back18Bump clap_complete from 4.2.0 to 4.2.1dependabot[bot]before adoptionab5ae5f
lines 19–21why, one step back19import matplotlib.pyplot as plt20import numpy as np21Support all exported metrics in plotting scripts (#981)David Peterbefore adoptionef86c83
line 22why, one step back22from plot_utils import METRICS, add_metric_argument, validate_metricBump clap_complete from 4.2.0 to 4.2.1dependabot[bot]before adoptionab5ae5f
line 23why, one step back23Support all exported metrics in plotting scripts (#981)David Peterbefore adoptionef86c83
lines 24–27why, one step back2425def moving_average(values, num_runs):26 values_padded = np.pad(27 values, (num_runs // 2, num_runs - 1 - num_runs // 2), mode="edge"Bump clap_complete from 4.2.0 to 4.2.1dependabot[bot]before adoptionab5ae5f
lines 28–29why, one step back28 )29 kernel = np.ones(num_runs) / num_runsSupport all exported metrics in plotting scripts (#981)David Peterbefore adoptionef86c83
line 30why, one step back30 return np.convolve(values_padded, kernel, mode="valid")Bump clap_complete from 4.2.0 to 4.2.1dependabot[bot]before adoptionab5ae5f
lines 31–33why, one step back313233parser = argparse.ArgumentParser(description=__doc__)Support all exported metrics in plotting scripts (#981)David Peterbefore adoptionef86c83
line 34why, one step back34add_metric_argument(parser)Bump clap_complete from 4.2.0 to 4.2.1dependabot[bot]before adoptionab5ae5f
lines 35–44why, one step back35parser.add_argument("file", help="JSON file with benchmark results")36parser.add_argument("--title", help="Plot Title")37parser.add_argument("-o", "--output", help="Save image to the given filename.")38parser.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)Improve plot_progression.py scriptDavid Peterbefore adoptionc7be935
lines 45–49why, one step back45parser.add_argument(46 "--no-moving-average",47 action="store_true",48 help="Do not show moving average curve",49)Bump clap_complete from 4.2.0 to 4.2.1dependabot[bot]before adoptionab5ae5f
line 50why, one step back50Improve plot_progression.py scriptDavid Peterbefore adoptionc7be935
line 51why, one step back51Bump clap_complete from 4.2.0 to 4.2.1dependabot[bot]before adoptionab5ae5f
line 52why, one step back52args = parser.parse_args()Support all exported metrics in plotting scripts (#981)David Peterbefore adoptionef86c83
line 53why, one step back53metric_label, metric_scale = METRICS[args.metric]Bump clap_complete from 4.2.0 to 4.2.1dependabot[bot]before adoptionab5ae5f
lines 54–56why, one step back5455with open(args.file) as f:56 results = json.load(f)["results"]Support all exported metrics in plotting scripts (#981)David Peterbefore adoptionef86c83
line 57why, one step back57validate_metric(parser, results, args.metric)Bump clap_complete from 4.2.0 to 4.2.1dependabot[bot]before adoptionab5ae5f
line 58why, one step back58Improve plot_progression.py scriptDavid Peterbefore adoptionc7be935
line 59why, one step back59for result in results:Merge pull request #790 from sharkdp/new-metricsDavid Peterbefore adoptionf26c015
line 60why, one step back60 label = result.get("name", result["command"])Support all exported metrics in plotting scripts (#981)David Peterbefore adoptionef86c83
lines 61–62why, one step back61 values = [m[args.metric]["value"] / metric_scale for m in result["measurements"]]62 num = len(values)Improve plot_progression.py scriptDavid Peterbefore adoptionc7be935
line 63why, one step back63 nums = range(num)Bump clap_complete from 4.2.0 to 4.2.1dependabot[bot]before adoptionab5ae5f
line 64why, one step back64Support all exported metrics in plotting scripts (#981)David Peterbefore adoptionef86c83
line 65why, one step back65 plt.scatter(x=nums, y=values, marker=".")Improve plot_progression.py scriptDavid Peterbefore adoptionc7be935
lines 66–67why, one step back66 plt.ylim([0, None])67 plt.xlim([-1, num])Bump clap_complete from 4.2.0 to 4.2.1dependabot[bot]before adoptionab5ae5f
line 68why, one step back68Improve plot_progression.py scriptDavid Peterbefore adoptionc7be935
lines 69–70why, one step back69 if not args.no_moving_average:70 moving_average_width = (Merge pull request #790 from sharkdp/new-metricsDavid Peterbefore adoptionf26c015
lines 71–73why, one step back71 max(1, num // 5)72 if args.moving_average_width is None73 else args.moving_average_widthImprove plot_progression.py scriptDavid Peterbefore adoptionc7be935
line 74why, one step back74 )Bump clap_complete from 4.2.0 to 4.2.1dependabot[bot]before adoptionab5ae5f
line 75why, one step back75Support all exported metrics in plotting scripts (#981)David Peterbefore adoptionef86c83
line 76why, one step back76 average = moving_average(values, moving_average_width)Improve plot_progression.py scriptDavid Peterbefore adoptionc7be935
line 77why, one step back77 plt.plot(nums, average, "-")Bump clap_complete from 4.2.0 to 4.2.1dependabot[bot]before adoptionab5ae5f
lines 78–80why, one step back7879if args.title:80 plt.title(args.title)Improve plot_progression.py scriptDavid Peterbefore adoptionc7be935
lines 81–83why, one step back8182legend = []83for result in results:Merge pull request #790 from sharkdp/new-metricsDavid Peterbefore adoptionf26c015
line 84why, one step back84 legend.append(result.get("name", result["command"]))Improve plot_progression.py scriptDavid Peterbefore adoptionc7be935
lines 85–88why, one step back85 if not args.no_moving_average:86 legend.append("moving average")87plt.legend(legend)88Support all exported metrics in plotting scripts (#981)David Peterbefore adoptionef86c83
line 89why, one step back89plt.ylabel(metric_label)Improve plot_progression.py scriptDavid Peterbefore adoptionc7be935
line 90why, one step back90Bump clap_complete from 4.2.0 to 4.2.1dependabot[bot]before adoptionab5ae5f
lines 91–94why, one step back91if args.output:92 plt.savefig(args.output)93else:94 plt.show()