plot_progression.py
This file
Path
scripts/plot_progression.py
87 lines · 2.0 KiB · Python
Last changed by
Sort importsDavid Peterbefore adoptionbc37eff
History of this fileTake it
The walk stopped after 200 commits: lines older than 2c174d4 point at it.
Bump serde from 1.0.163 to 1.0.164dependabot[bot]before adoption2c174d4
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.163 to 1.0.164dependabot[bot]before adoption2c174d4
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 serde from 1.0.163 to 1.0.164dependabot[bot]before adoption2c174d4
lines 19–41why, one step back19import matplotlib.pyplot as plt20import numpy as np212223def moving_average(times, num_runs):24 times_padded = np.pad(25 times, (num_runs // 2, num_runs - 1 - num_runs // 2), mode="edge"26 )27 kernel = np.ones(num_runs) / num_runs28 return np.convolve(times_padded, kernel, mode="valid")293031parser = argparse.ArgumentParser(description=__doc__)32parser.add_argument("file", help="JSON file with benchmark results")33parser.add_argument("--title", help="Plot Title")34parser.add_argument("-o", "--output", help="Save image to the given filename.")35parser.add_argument(36 "-w",37 "--moving-average-width",38 type=int,39 metavar="num_runs",40 help="Width of the moving-average window (default: N/5)",41)Improve plot_progression.py scriptDavid Peterbefore adoptionc7be935
lines 42–46why, one step back42parser.add_argument(43 "--no-moving-average",44 action="store_true",45 help="Do not show moving average curve",46)Bump serde from 1.0.163 to 1.0.164dependabot[bot]before adoption2c174d4
line 47why, one step back47Improve plot_progression.py scriptDavid Peterbefore adoptionc7be935
line 48why, one step back48Bump serde from 1.0.163 to 1.0.164dependabot[bot]before adoption2c174d4
lines 49–53why, one step back49args = parser.parse_args()5051with open(args.file) as f:52 results = json.load(f)["results"]53Improve plot_progression.py scriptDavid Peterbefore adoptionc7be935
lines 54–58why, one step back54for result in results:55 label = result["command"]56 times = result["times"]57 num = len(times)58 nums = range(num)Bump serde from 1.0.163 to 1.0.164dependabot[bot]before adoption2c174d4
line 59why, one step back59Improve plot_progression.py scriptDavid Peterbefore adoptionc7be935
lines 60–62why, one step back60 plt.scatter(x=nums, y=times, marker=".")61 plt.ylim([0, None])62 plt.xlim([-1, num])Bump serde from 1.0.163 to 1.0.164dependabot[bot]before adoption2c174d4
line 63why, one step back63Improve plot_progression.py scriptDavid Peterbefore adoptionc7be935
lines 64–67why, one step back64 if not args.no_moving_average:65 moving_average_width = (66 num // 5 if args.moving_average_width is None else args.moving_average_width67 )Bump serde from 1.0.163 to 1.0.164dependabot[bot]before adoption2c174d4
line 68why, one step back68Improve plot_progression.py scriptDavid Peterbefore adoptionc7be935
lines 69–70why, one step back69 average = moving_average(times, moving_average_width)70 plt.plot(nums, average, "-")Bump serde from 1.0.163 to 1.0.164dependabot[bot]before adoption2c174d4
lines 71–73why, one step back7172if args.title:73 plt.title(args.title)Improve plot_progression.py scriptDavid Peterbefore adoptionc7be935
lines 74–81why, one step back7475legend = []76for result in results:77 legend.append(result["command"])78 if not args.no_moving_average:79 legend.append("moving average")80plt.legend(legend)81Bump serde from 1.0.163 to 1.0.164dependabot[bot]before adoption2c174d4
line 82why, one step back82plt.ylabel("Time [s]")Improve plot_progression.py scriptDavid Peterbefore adoptionc7be935
line 83why, one step back83Bump serde from 1.0.163 to 1.0.164dependabot[bot]before adoption2c174d4
lines 84–87why, one step back84if args.output:85 plt.savefig(args.output)86else:87 plt.show()