-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshowGraph.py
130 lines (108 loc) · 4.03 KB
/
showGraph.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
import matplotlib.pyplot as plt
name_map = dict()
def trans(bench_name):
res = []
for i in bench_name:
if 'Basic' in i:
res.append('default')
elif 'random' in i:
res.append('random')
elif 'max_hei' in i:
res.append('deepest')
elif 'Linear' in i:
res.append('blocking linear op')
elif 'STLB' in i:
res.append('STLB')
return res
def plot_results(name, results):
bench_name = []
max_heights = []
max_rotations = []
sum_rotations = []
times = []
for result in results:
bench_name.append(result['bench-name'])
max_heights.append(result['max-height'])
max_rotations.append(result['max-rotation'])
sum_rotations.append(result['sum-rotation'])
times.append(result['ns/op'])
fig, ax1 = plt.subplots(figsize=(12, 8))
# bench_name = [name_map[i] for i in bench_name]
bench_name = trans(bench_name)
# print(bench_name)
# max height
ax1.plot(bench_name, max_heights, marker='o', color='#1f77b4', label='max height')
ax1.set_xlabel('Splay trees')
ax1.set_ylabel('max heights', color='#1f77b4')
ax1.tick_params(axis='y', labelcolor='#1f77b4')
# sum rotations
ax2 = ax1.twinx()
ax2.plot(bench_name, sum_rotations, marker='^', color='#2ca02c', label='count of rotation calls')
ax2.set_ylabel('rotation counts', color='#2ca02c')
ax2.tick_params(axis='y', labelcolor='#2ca02c')
# time
ax3 = ax1.twinx()
ax3.spines['right'].set_position(('outward', 60))
ax3.plot(bench_name, times, marker='x', color='#9467bd', label='ns/op')
ax3.set_ylabel('ns / op', color='#9467bd')
ax3.tick_params(axis='y', labelcolor='#9467bd')
# max rotaion
ax4 = ax1.twinx()
ax4.spines['right'].set_position(('outward', 120))
ax4.plot(bench_name, max_rotations, marker='x', color='#ff7f0e', label='ns/op')
ax4.set_ylabel('rotation', color='#ff7f0e')
ax4.tick_params(axis='y', labelcolor='#ff7f0e')
plt.title(name[:-4])
fig.tight_layout()
ax1.legend(loc='upper left')
ax2.legend(loc='upper center')
ax3.legend(loc='upper right')
ax4.legend(loc='upper right')
plt.savefig('result/'+name[:-4])
def parse_bench_file(filename):
res=[{"benchmark":"", "results":[], "ns/op":""}]
with open(filename, 'r') as f:
for line in f:
if line[:9] == "Benchmark":
res.append({
"benchmark":line,
"results":[],
"ns/op": ""
})
elif line[:6] == 'result':
res[-1]['results'].append(line)
elif line[:8] == '10000000':
res[-1]['ns/op'] = line
bench_result = []
for result in res:
if result['benchmark'] != '' and len(result['results'])>0:
mxH,mxR,sumR=0,0,0
if len(result['results']) == 8:
result['results'] = result['results'][:-1]
for re in result['results']:
h,r,sr=map(int,re[7:-2].split(','))
mxH+=h
mxR+=r
sumR+=sr
mxH/=len(result['results'])
mxR/=len(result['results'])
sumR/=len(result['results'])
bench_result.append({
'bench-name': result['benchmark'].strip(),
'max-height': mxH,
'max-rotation': mxR,
'sum-rotation': sumR,
'ns/op': float(result['ns/op'].split()[1])
})
return bench_result
if __name__ == "__main__":
defulat_res = parse_bench_file('result/basic-tree-result.txt')
# with open('result/splay-tree-numbers.txt', 'r') as f:
# for line in f:
# n, nm=line.split()
# name_map[nm]=n
# for file in ['random-result.txt', 'max-height-splay-result.txt', 'stlb-result.txt', 'result.txt']:
file = 'tot_res'
res = parse_bench_file(file)
res = defulat_res + res
plot_results(file, res)