Skip to content
Myr

plot_progression.py

This file

Path

scripts/plot_progression.py

62 lines · 1.6 KiB · Python

Last changed by

Add plot_progression.pyDavid Peterbefore adoptionf1557d4

History of this file

Take it

Add plot_progression.pyDavid Peterbefore adoptionf1557d4

lines 1–62why, one step back
1#!/usr/bin/env python
23"""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)3334args = parser.parse_args()3536with open(args.file) as f:37 results = json.load(f)["results"]3839label = results[0]["command"]40times = results[0]["times"]41num = len(times)42nums = range(num)4344plt.scatter(x=nums, y=times, marker=".", color="orange")45plt.ylim([0, None])46plt.xlim([-1, num])4748moving_average_width = (49 num // 5 if args.moving_average_width is None else args.moving_average_width50)5152moving_average = moving_average(times, moving_average_width)53plt.plot(nums, moving_average, "-", color="blue")5455if args.title:56 plt.title(args.title)57plt.legend(labels=[label], loc="best", fontsize="medium")58plt.ylabel("Time [s]")59if args.output:60 plt.savefig(args.output)61else:62 plt.show()