forked from sampsyo/llvm-pass-skeleton
-
Notifications
You must be signed in to change notification settings - Fork 1
/
process_csv.py
53 lines (50 loc) · 1.74 KB
/
process_csv.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
import os
import statistics
import sys
def get_mean_std(out_csv):
with open(out_csv) as f:
lines = f.readlines()
tests = dict()
for t in lines[1:]:
t = t.split(",")
test_name = t[0].strip()
opt = float(t[2].strip())
tests[test_name] = tests.get(test_name, list()) + [opt]
means = {t: sum(v)/len(v) for t, v in tests.items()}
std = {t: statistics.stdev(v) for t, v in tests.items()}
return means
def get_tests(out_csv):
tests = set()
orig = dict()
with open(out_csv) as f:
lines = f.readlines()
for l in lines[1:]:
l = l.split(",")
name = l[0].strip()
original_runtime = float(l[1].strip())
tests.add(name)
orig[name] = orig.get(name, list()) + [original_runtime]
tests = sorted(list(tests))
means = {t: sum(v)/len(v) for t, v in orig.items()}
std = {t: statistics.stdev(v) for t, v in orig.items()}
return [[t, str(means[t])] for t in tests]
if __name__ == '__main__':
if len(sys.argv) != 2:
print("Usage: python3 process_csv.py [output_csv_path]")
sys.exit(1)
num_runs = (1, 2, 3)
thresholds = (10, 100, 1000)
filename = lambda runs, threshold: f'out-{runs}-{threshold}.csv'
output_file = sys.argv[1]
header = ['test', 'original']
tests = get_tests('out-1-10.csv')
for threshold in thresholds:
for run in num_runs:
out_csv = filename(run, threshold)
stat = get_mean_std(out_csv)
header += [f'runs:{run}+thresh:{threshold}']
tests = [row + [str(stat[row[0]])] for row in tests]
with open(output_file, 'w') as f:
f.write(', '.join(header) + '\n')
for row in tests:
f.write(', '.join(row) + '\n')