-
-
Notifications
You must be signed in to change notification settings - Fork 472
Expand file tree
/
Copy pathplot_progression.py
More file actions
executable file
·87 lines (69 loc) · 2.03 KB
/
plot_progression.py
File metadata and controls
executable file
·87 lines (69 loc) · 2.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/usr/bin/env python
# /// script
# requires-python = ">=3.10"
# dependencies = [
# "pyqt6",
# "matplotlib",
# "numpy",
# ]
# ///
"""This program shows `hyperfine` benchmark results in a sequential way
in order to debug possible background interference, caching effects,
thermal throttling and similar effects.
"""
import argparse
import json
import matplotlib.pyplot as plt
import numpy as np
def moving_average(times, num_runs):
times_padded = np.pad(
times, (num_runs // 2, num_runs - 1 - num_runs // 2), mode="edge"
)
kernel = np.ones(num_runs) / num_runs
return np.convolve(times_padded, kernel, mode="valid")
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("file", help="JSON file with benchmark results")
parser.add_argument("--title", help="Plot Title")
parser.add_argument("-o", "--output", help="Save image to the given filename.")
parser.add_argument(
"-w",
"--moving-average-width",
type=int,
metavar="num_runs",
help="Width of the moving-average window (default: N/5)",
)
parser.add_argument(
"--no-moving-average",
action="store_true",
help="Do not show moving average curve",
)
args = parser.parse_args()
with open(args.file) as f:
results = json.load(f)["results"]
for result in results:
label = result["command"]
times = result["times"]
num = len(times)
nums = range(num)
plt.scatter(x=nums, y=times, marker=".")
plt.ylim([0, None])
plt.xlim([-1, num])
if not args.no_moving_average:
moving_average_width = (
num // 5 if args.moving_average_width is None else args.moving_average_width
)
average = moving_average(times, moving_average_width)
plt.plot(nums, average, "-")
if args.title:
plt.title(args.title)
legend = []
for result in results:
legend.append(result["command"])
if not args.no_moving_average:
legend.append("moving average")
plt.legend(legend)
plt.ylabel("Time [s]")
if args.output:
plt.savefig(args.output)
else:
plt.show()