-
Notifications
You must be signed in to change notification settings - Fork 2
/
graph.py
executable file
·79 lines (58 loc) · 2.09 KB
/
graph.py
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
#!/usr/bin/env python3
import csv, sys
from decimal import Decimal
def avg(d):
return {k: sum(v)/len(v) for (k, v) in d.items()}
def calculate(path):
scores = {}
refs = {}
with open(path, 'r') as f:
reader = csv.reader(f)
next(reader)
for row in reader:
segments = tuple(row[0].split('.')[-1].split('_'))
d = refs if segments[-1] == 'ref' else scores
d.setdefault(segments[0], []).append(Decimal(row[-3]))
scores = avg(scores)
refs = avg(refs)
for (meth, mean) in scores.items():
change = (mean - refs[meth]) / refs[meth] * 100
yield (meth, change)
if __name__ == '__main__':
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import ticker, rc
import pprint, itertools
data = {sys.argv[i]: sorted(calculate(sys.argv[i+1]), key=lambda t: t[0])
for i in range(1, len(sys.argv), 2)}
mmax = float(max(list(zip(*itertools.chain(*data.values())))[1]))
mmin = float(min(list(zip(*itertools.chain(*data.values())))[1]))
pprint.pprint(data)
N = len(list(data.values())[0])
ind = np.arange(N)
width = 0.35
colors = itertools.cycle(('#9edeff', '#ff9ede'))
FONT = 'Droid Sans Mono'
rc('font', family=FONT)
(fig, ax) = plt.subplots()
ax.tick_params(labeltop=False, top=False, bottom=False)
rects = []
for (i, (tag, xs)) in enumerate(sorted(data.items(), key=lambda t: t[0])):
color = next(colors)
r = ax.bar(ind + (i * width), list(zip(*xs))[1], width, color=color)
rects.append((r, tag))
ax.set_title("UInt256 Throughput Increase\nvs. OpenJDK's BigInteger")
labels = list(zip(*list(data.values())[0]))[0]
ax.set_xticks(ind, top=False)
ax.set_xticklabels(labels, rotation=90)
ax.tick_params(axis='x', top=False, labeltop=False)
def yformat(v, pos):
return '%s%d%% ' % ('+' if 0 < v else '', v)
ax.yaxis.set_major_formatter(ticker.FuncFormatter(yformat))
ax.spines[['top']].set_visible(False)
ax.legend(
*zip(*tuple((r[0], l) for (r, l) in rects)),
frameon=False)
ax.axhline(0, color='k')
plt.tight_layout()
plt.savefig('out.png', transparent=True)