Skip to content
Myr

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 file

Take it

The walk stopped after 200 commits: lines older than 30d2253 point at it.

Add hint to --time-unitEngineer-of-Efficiencybefore adoption30d2253

lines 1–32why, 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)

Improve plot_progression.py scriptDavid Peterbefore adoptionc7be935

lines 33–37why, one step back
33parser.add_argument(
34 "--no-moving-average",35 action="store_true",36 help="Do not show moving average curve",37)

Add hint to --time-unitEngineer-of-Efficiencybefore adoption30d2253

line 38why, one step back
38

Improve plot_progression.py scriptDavid Peterbefore adoptionc7be935

line 39why, one step back
39

Add hint to --time-unitEngineer-of-Efficiencybefore adoption30d2253

lines 40–44why, one step back
40args = parser.parse_args()
4142with open(args.file) as f:43 results = json.load(f)["results"]44

Improve plot_progression.py scriptDavid Peterbefore adoptionc7be935

lines 45–49why, one step back
45for result in results:
46 label = result["command"]47 times = result["times"]48 num = len(times)49 nums = range(num)

Add hint to --time-unitEngineer-of-Efficiencybefore adoption30d2253

line 50why, one step back
50

Improve plot_progression.py scriptDavid Peterbefore adoptionc7be935

lines 51–53why, one step back
51 plt.scatter(x=nums, y=times, marker=".")
52 plt.ylim([0, None])53 plt.xlim([-1, num])

Add hint to --time-unitEngineer-of-Efficiencybefore adoption30d2253

line 54why, one step back
54

Improve plot_progression.py scriptDavid Peterbefore adoptionc7be935

lines 55–58why, one step back
55 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 )

Add hint to --time-unitEngineer-of-Efficiencybefore adoption30d2253

line 59why, one step back
59

Improve plot_progression.py scriptDavid Peterbefore adoptionc7be935

lines 60–61why, one step back
60 average = moving_average(times, moving_average_width)
61 plt.plot(nums, average, "-")

Add hint to --time-unitEngineer-of-Efficiencybefore adoption30d2253

lines 62–64why, one step back
62
63if args.title:64 plt.title(args.title)

Improve plot_progression.py scriptDavid Peterbefore adoptionc7be935

lines 65–72why, one step back
65
66legend = []67for result in results:68 legend.append(result["command"])69 if not args.no_moving_average:70 legend.append("moving average")71plt.legend(legend)72

Add hint to --time-unitEngineer-of-Efficiencybefore adoption30d2253

line 73why, one step back
73plt.ylabel("Time [s]")

Improve plot_progression.py scriptDavid Peterbefore adoptionc7be935

line 74why, one step back
74

Add hint to --time-unitEngineer-of-Efficiencybefore adoption30d2253

lines 75–78why, one step back
75if args.output:
76 plt.savefig(args.output)77else:78 plt.show()