-
Notifications
You must be signed in to change notification settings - Fork 16
/
benchread.py
91 lines (81 loc) · 2.57 KB
/
benchread.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
import re
header = """
\\begin{tabular}{|l|r|r|r|r|r|}
\\hline
{\\it name} & {\\it staging} & {\\it staged} & {\\it run-staged} & {\\it unstaged} & {\\it gain}\\\\
\\hline
"""
footer = """
\\end{tabular}
"""
re_bench = re.compile(r'^BENCH (?P<phase>\S+) (?P<name>\S+)( (?P<id>\S+))?$')
#re_time = re.compile(r'\s*(?P<time>\d+\.\d+)s elapsed cpu time')
re_time = re.compile(r'\s*cpu time:\s*(?P<time>\d+)')
re_int_count = re.compile(r'^generated code u-eval-expo count: (?P<count>\d+)')
#MAX_TIME = 100000.0
MAX_TIME = 100000
all_phases = ['staging', 'staged', 'run-staged', 'unstaged']
all_times = {}
all_int_counts = {}
all_names = []
all_ids = []
cur_phase = None
cur_name = None
cur_id = None
print(header)
for line in open('bench-log-ex.txt'):
m = re_bench.match(line)
if m:
cur_phase = m['phase']
assert cur_phase in all_phases, "invalid phase %s" % (cur_phase)
cur_name = m['name']
cur_id = m['id']
if cur_name not in all_names:
all_names.append(cur_name)
if cur_id not in all_ids:
all_ids.append(cur_id)
continue
key = (cur_name, cur_phase, cur_id)
m = re_time.match(line)
if m:
time = int(m['time'])
all_times[key] = time
m = re_int_count.match(line)
if m:
int_count = int(m['count'])
all_int_counts[key] = int_count
for name in all_names:
for id in all_ids:
s = name
if id:
s += ' (%s)' % id
times = {}
for phase in all_phases:
s += ' & '
key = (name, phase, id)
if key in all_times:
time = all_times[key]
times[phase] = time
s += '$%d$ms' % time
elif (phase == 'unstaged' and (
(name, 'staged', id) in all_times or
(name, 'run-staged', id) in all_times)):
s += '\\timeout{$>5$ min}'
if key in all_int_counts:
s += ' ($%d$)' % all_int_counts[key]
s += ' & '
if times:
min_time = min(times.get('staged', MAX_TIME),
times.get('run-staged', MAX_TIME))
if 0 < min_time:
if min_time < MAX_TIME:
if 'unstaged' in times:
gain = (1.0*times['unstaged']) / min_time
s += '$%.3f$' % gain
else:
gain = 5*60*1000 / min_time
s += '\\timeout{>$%.3f$}' % gain
s += '\\\\'
print(s)
print('\\hline')
print(footer)