forked from sampsyo/bril
-
Notifications
You must be signed in to change notification settings - Fork 0
/
normalize.py
45 lines (37 loc) · 1.03 KB
/
normalize.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
import csv
import sys
from collections import defaultdict
from statistics import geometric_mean
STATS = {
'geomean': geometric_mean,
'min': min,
'max': max,
}
def normalize():
# Read input CSV.
reader = csv.DictReader(sys.stdin)
in_data = list(reader)
# Get normalization baselines.
baselines = {
row['benchmark']: int(row['result'])
for row in in_data
if row['run'] == 'baseline'
}
# Write output CSV back out.
writer = csv.DictWriter(sys.stdout, reader.fieldnames)
writer.writeheader()
ratios = defaultdict(list)
for row in in_data:
ratio = int(row['result']) / baselines[row['benchmark']]
ratios[row['run']].append(ratio)
row['result'] = ratio
writer.writerow(row)
# Print stats.
for run, rs in ratios.items():
for name, func in STATS.items():
print(
'{}({}) = {:.2f}'.format(name, run, func(rs)),
file=sys.stderr,
)
if __name__ == '__main__':
normalize()