plot_progression.py
This file
Path
scripts/plot_progression.py
78 lines · 1.9 KiB · Python
Last changed by
Improve plot_progression.py scriptDavid Peterbefore adoptionc7be935
History of this fileTake it
The walk stopped after 200 commits: lines older than b924033 point at it.
Bump anyhow from 1.0.56 to 1.0.57dependabot[bot]before adoptionb924033
lines 1–32why, one step back1#!/usr/bin/env python23"""This program shows `hyperfine` benchmark results in a sequential way4in order to debug possible background interference, caching effects,5thermal throttling and similar effects.6"""78import argparse9import json10import matplotlib.pyplot as plt11import numpy as np121314def moving_average(times, num_runs):15 times_padded = np.pad(16 times, (num_runs // 2, num_runs - 1 - num_runs // 2), mode="edge"17 )18 kernel = np.ones(num_runs) / num_runs19 return np.convolve(times_padded, kernel, mode="valid")202122parser = argparse.ArgumentParser(description=__doc__)23parser.add_argument("file", help="JSON file with benchmark results")24parser.add_argument("--title", help="Plot Title")25parser.add_argument("-o", "--output", help="Save image to the given filename.")26parser.add_argument(27 "-w",28 "--moving-average-width",29 type=int,30 metavar="num_runs",31 help="Width of the moving-average window (default: N/5)",32)Improve plot_progression.py scriptDavid Peterbefore adoptionc7be935
lines 33–37why, one step back33parser.add_argument(34 "--no-moving-average",35 action="store_true",36 help="Do not show moving average curve",37)Bump anyhow from 1.0.56 to 1.0.57dependabot[bot]before adoptionb924033
line 38why, one step back38Improve plot_progression.py scriptDavid Peterbefore adoptionc7be935
line 39why, one step back39Bump anyhow from 1.0.56 to 1.0.57dependabot[bot]before adoptionb924033
lines 40–44why, one step back40args = parser.parse_args()4142with open(args.file) as f:43 results = json.load(f)["results"]44Improve plot_progression.py scriptDavid Peterbefore adoptionc7be935
lines 45–49why, one step back45for result in results:46 label = result["command"]47 times = result["times"]48 num = len(times)49 nums = range(num)Bump anyhow from 1.0.56 to 1.0.57dependabot[bot]before adoptionb924033
line 50why, one step back50Improve plot_progression.py scriptDavid Peterbefore adoptionc7be935
lines 51–53why, one step back51 plt.scatter(x=nums, y=times, marker=".")52 plt.ylim([0, None])53 plt.xlim([-1, num])Bump anyhow from 1.0.56 to 1.0.57dependabot[bot]before adoptionb924033
line 54why, one step back54Improve plot_progression.py scriptDavid Peterbefore adoptionc7be935
lines 55–58why, one step back55 if not args.no_moving_average:56 moving_average_width = (57 num // 5 if args.moving_average_width is None else args.moving_average_width58 )Bump anyhow from 1.0.56 to 1.0.57dependabot[bot]before adoptionb924033
line 59why, one step back59Improve plot_progression.py scriptDavid Peterbefore adoptionc7be935
lines 60–61why, one step back60 average = moving_average(times, moving_average_width)61 plt.plot(nums, average, "-")Bump anyhow from 1.0.56 to 1.0.57dependabot[bot]before adoptionb924033
lines 62–64why, one step back6263if args.title:64 plt.title(args.title)Improve plot_progression.py scriptDavid Peterbefore adoptionc7be935
lines 65–72why, one step back6566legend = []67for result in results:68 legend.append(result["command"])69 if not args.no_moving_average:70 legend.append("moving average")71plt.legend(legend)72Bump anyhow from 1.0.56 to 1.0.57dependabot[bot]before adoptionb924033
line 73why, one step back73plt.ylabel("Time [s]")Improve plot_progression.py scriptDavid Peterbefore adoptionc7be935
line 74why, one step back74Bump anyhow from 1.0.56 to 1.0.57dependabot[bot]before adoptionb924033
lines 75–78why, one step back75if args.output:76 plt.savefig(args.output)77else:78 plt.show()