-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcomp_analysis.py
139 lines (122 loc) · 4.97 KB
/
comp_analysis.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
131
132
133
134
135
136
137
138
139
#!/usr/bin/python3
import numpy as np
import sys
import matplotlib.pyplot as plt
import config
def get_improvement(hi, lo, performance):
"""
Get improvement from two execution speeds.
Arguments:
hi, lo: (double) execution speeds
performance: (bool) True if calculating performance increase, False if calculating time reduction.
Returns: (double) Calculated improvement
"""
if (lo > hi):
print('input order incorrect')
sys.exit()
return 100 * (hi - lo) / (lo if performance else hi)
def generate_data():
data = {}
config.init()
for filename in config.file_struct.keys():
raw_data = np.genfromtxt(filename, delimiter=',')
data[filename] = (np.mean(raw_data), raw_data)
return data
def generate_txt(data):
"""
Generate output .txt file
Arguments:
data = {filename: (average execution time, [raw data])}
"""
native_comp_p = get_improvement(
data[config.native_no_sse_fn][0], data[config.native_sse_fn][0], True)
wasm_comp_p = get_improvement(
data[config.wasm_no_simd_fn][0], data[config.wasm_simd_fn][0], True)
simd_comp_p = get_improvement(
data[config.wasm_simd_fn][0], data[config.native_sse_fn][0], True)
no_simd_comp_p = get_improvement(
data[config.wasm_no_simd_fn][0], data[config.native_no_sse_fn][0], True)
native_comp_t = get_improvement(
data[config.native_no_sse_fn][0], data[config.native_sse_fn][0], False)
wasm_comp_t = get_improvement(
data[config.wasm_no_simd_fn][0], data[config.wasm_simd_fn][0], False)
simd_comp_t = get_improvement(
data[config.wasm_simd_fn][0], data[config.native_sse_fn][0], False)
no_simd_comp_t = get_improvement(
data[config.wasm_no_simd_fn][0], data[config.native_no_sse_fn][0], False)
with open(config.comp_struct[0], 'w') as f:
f.write("averages: \n")
f.write(" native without sse2 : " +
str(data[config.native_no_sse_fn][0]) + "\n")
f.write(" native with sse2 : " +
str(data[config.native_sse_fn][0]) + "\n")
f.write(" wasm without simd128 : " +
str(data[config.wasm_no_simd_fn][0]) + "\n")
f.write(" wasm with simd128 : " +
str(data[config.wasm_simd_fn][0]) + "\n")
f.write("\n")
f.write("performance increase percentage [100 * (hi - lo) / lo]: \n")
f.write(" native without sse2 -> native with sse2 : " +
str(native_comp_p) + "\n")
f.write(" wasm without simd128 -> wasm with simd128 : " +
str(wasm_comp_p) + "\n")
f.write(" wasm with simd128 -> native with sse2 : " +
str(simd_comp_p) + "\n")
f.write(" wasm without simd128 -> native without sse2 : " +
str(no_simd_comp_p) + "\n")
f.write("\n")
f.write("time reduction percentage [100 * (hi - lo) / hi]: \n")
f.write(" native without sse2 -> native with sse2 : " +
str(native_comp_t) + "\n")
f.write(" wasm without simd128 -> wasm with simd128 : " +
str(wasm_comp_t) + "\n")
f.write(" wasm with simd128 -> native with sse2 : " +
str(simd_comp_t) + "\n")
f.write(" wasm without simd128 -> native without sse2 : " +
str(no_simd_comp_t) + "\n")
def generate_plt(data):
"""
Generate output histogram .png file
Arguments:
data = {filename: (average execution time, [raw data])}
"""
bins = np.arange(config.MIN, config.MAX, config.delta)
plt.hist(data[config.native_no_sse_fn][1], bins, alpha=config.alpha,
label=config.comp_struct[1][0], edgecolor="black")
plt.hist(data[config.native_sse_fn][1], bins, alpha=config.alpha,
label=config.comp_struct[1][1], edgecolor="black")
plt.hist(data[config.wasm_no_simd_fn][1], bins, alpha=config.alpha,
label=config.comp_struct[1][2], edgecolor="black")
plt.hist(data[config.wasm_simd_fn][1], bins, alpha=config.alpha,
label=config.comp_struct[1][3], edgecolor="black")
plt.xlabel("Time [s]")
plt.ylabel("Frequency")
plt.legend(loc='upper left', fontsize='small')
plt.title(config.comp_struct[2])
plt.savefig(config.comp_struct[3])
def generate_bar(data):
"""
Generate output bar chart .png file
Arguments:
data = {filename: (average execution time, [raw data])}
"""
x_axis = config.comp_struct[5]
y_axis = np.zeros(4)
for i in range(4):
y_axis[i + 1 if i % 2 == 0 else i - 1] = list(data.values())[i][0]
print(x_axis)
print(y_axis)
plt.figure(figsize=config.fig_size)
plt.bar(x_axis, y_axis)
plt.xlabel('Implementation')
plt.ylabel('Time [s]')
plt.title(config.comp_struct[2])
plt.savefig(config.comp_struct[4])
def main():
data = generate_data()
generate_txt(data)
generate_plt(data)
plt.close()
generate_bar(data)
if __name__ == "__main__":
main()