forked from psf/pyperf
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot.py
More file actions
executable file
·83 lines (71 loc) · 2.43 KB
/
Copy pathplot.py
File metadata and controls
executable file
·83 lines (71 loc) · 2.43 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
#!/usr/bin/env python3
import argparse
import matplotlib.pyplot as plt
import pyperf
import statistics
def plot_bench(args, bench):
if not args.split_runs:
runs = bench.get_runs()
if args.run:
run = runs[args.run - 1]
runs = [run]
values = []
for run in runs:
run_values = run.values
if args.skip:
run_values = run_values[args.skip:]
values.extend(run_values)
plt.plot(values, label='values')
mean = statistics.mean(values)
plt.plot([mean] * len(values), label='mean')
else:
values = []
width = None
for run_index, run in enumerate(bench.get_runs()):
index = 0
x = []
y = []
run_values = run.values
if args.skip:
run_values = run_values[args.skip:]
for value in run_values:
x.append(index)
y.append(value)
index += 1
plt.plot(x, y, color='blue')
values.extend(run_values)
width = len(run_values)
if args.warmups:
run_values = [value for loops, value in run.warmups]
index = -len(run.warmups) + 1
x = []
y = []
for value in run_values:
x.append(index)
y.append(value)
index += 1
plt.plot(x, y, color='red')
mean = statistics.mean(values)
plt.plot([mean] * width, label='mean', color='green')
plt.legend(loc='upper right', shadow=True, fontsize='x-large')
plt.show()
def parse_args():
parser = argparse.ArgumentParser()
parser.add_argument('-b', '--benchmark')
parser.add_argument('--split-runs', action='store_true')
parser.add_argument('--skip', type=int, help='skip first SKIP values')
parser.add_argument('--warmups', action='store_true')
parser.add_argument('--run', metavar='INDEX', type=int,
help='only render run number INDEX')
parser.add_argument('filename')
return parser.parse_args()
def main():
args = parse_args()
if args.benchmark:
suite = pyperf.BenchmarkSuite.load(args.filename)
bench = suite.get_benchmark(args.benchmark)
else:
bench = pyperf.Benchmark.load(args.filename)
plot_bench(args, bench)
if __name__ == "__main__":
main()