plot_progression.py
This file
Path
scripts/plot_progression.py
90 lines · 2.3 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–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–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 clap_complete from 4.2.0 to 4.2.1dependabot[bot]before adoptionab5ae5f
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 clap_complete from 4.2.0 to 4.2.1dependabot[bot]before adoptionab5ae5f
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 clap_complete from 4.2.0 to 4.2.1dependabot[bot]before adoptionab5ae5f
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 clap_complete from 4.2.0 to 4.2.1dependabot[bot]before adoptionab5ae5f
lines 30–32why, one step back303132parser = argparse.ArgumentParser(description=__doc__)Support all exported metrics in plotting scripts (#981)David Peterbefore adoptionef86c83
line 33why, one step back33add_metric_argument(parser)Bump clap_complete from 4.2.0 to 4.2.1dependabot[bot]before adoptionab5ae5f
lines 34–43why, one step back34parser.add_argument("file", help="JSON file with benchmark results")35parser.add_argument("--title", help="Plot Title")36parser.add_argument("-o", "--output", help="Save image to the given filename.")37parser.add_argument(38 "-w",39 "--moving-average-width",40 type=int,41 metavar="num_runs",42 help="Width of the moving-average window (default: N/5)",43)Improve plot_progression.py scriptDavid Peterbefore adoptionc7be935
lines 44–48why, one step back44parser.add_argument(45 "--no-moving-average",46 action="store_true",47 help="Do not show moving average curve",48)Bump clap_complete from 4.2.0 to 4.2.1dependabot[bot]before adoptionab5ae5f
line 49why, one step back49Improve plot_progression.py scriptDavid Peterbefore adoptionc7be935
line 50why, one step back50Bump clap_complete from 4.2.0 to 4.2.1dependabot[bot]before adoptionab5ae5f
line 51why, one step back51args = parser.parse_args()Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
lines 52–53why, one step back52metric, [results] = load_results(parser, [args.file], args.metric)53metric_info = METRICS[metric]Bump clap_complete from 4.2.0 to 4.2.1dependabot[bot]before adoptionab5ae5f
line 54why, one step back54Improve plot_progression.py scriptDavid Peterbefore adoptionc7be935
line 55why, one step back55for result in results:Merge pull request #790 from sharkdp/new-metricsDavid Peterbefore adoptionf26c015
line 56why, one step back56 label = result.get("name", result["command"])Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
line 57why, one step back57 values = [m[metric]["value"] / metric_info.scale for m in result["measurements"]]Support all exported metrics in plotting scripts (#981)David Peterbefore adoptionef86c83
line 58why, one step back58 num = len(values)Improve plot_progression.py scriptDavid Peterbefore adoptionc7be935
line 59why, one step back59 nums = range(num)Bump clap_complete from 4.2.0 to 4.2.1dependabot[bot]before adoptionab5ae5f
line 60why, one step back60Support all exported metrics in plotting scripts (#981)David Peterbefore adoptionef86c83
line 61why, one step back61 plt.scatter(x=nums, y=values, marker=".")Improve plot_progression.py scriptDavid Peterbefore adoptionc7be935
lines 62–63why, one step back62 plt.ylim([0, None])63 plt.xlim([-1, num])Bump clap_complete from 4.2.0 to 4.2.1dependabot[bot]before adoptionab5ae5f
line 64why, one step back64Improve plot_progression.py scriptDavid Peterbefore adoptionc7be935
lines 65–66why, one step back65 if not args.no_moving_average:66 moving_average_width = (Merge pull request #790 from sharkdp/new-metricsDavid Peterbefore adoptionf26c015
lines 67–69why, one step back67 max(1, num // 5)68 if args.moving_average_width is None69 else args.moving_average_widthImprove plot_progression.py scriptDavid Peterbefore adoptionc7be935
line 70why, one step back70 )Bump clap_complete from 4.2.0 to 4.2.1dependabot[bot]before adoptionab5ae5f
line 71why, one step back71Support all exported metrics in plotting scripts (#981)David Peterbefore adoptionef86c83
line 72why, one step back72 average = moving_average(values, moving_average_width)Improve plot_progression.py scriptDavid Peterbefore adoptionc7be935
line 73why, one step back73 plt.plot(nums, average, "-")Bump clap_complete from 4.2.0 to 4.2.1dependabot[bot]before adoptionab5ae5f
lines 74–76why, one step back7475if args.title:76 plt.title(args.title)Improve plot_progression.py scriptDavid Peterbefore adoptionc7be935
lines 77–79why, one step back7778legend = []79for result in results:Merge pull request #790 from sharkdp/new-metricsDavid Peterbefore adoptionf26c015
line 80why, one step back80 legend.append(result.get("name", result["command"]))Improve plot_progression.py scriptDavid Peterbefore adoptionc7be935
lines 81–84why, one step back81 if not args.no_moving_average:82 legend.append("moving average")83plt.legend(legend)84Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
line 85why, one step back85plt.ylabel(metric_info.axis_label)Improve plot_progression.py scriptDavid Peterbefore adoptionc7be935
line 86why, one step back86Bump clap_complete from 4.2.0 to 4.2.1dependabot[bot]before adoptionab5ae5f
lines 87–90why, one step back87if args.output:88 plt.savefig(args.output)89else:90 plt.show()