forked from svaarala/duktape
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathformat_perftest.py
148 lines (122 loc) · 4.7 KB
/
format_perftest.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
140
141
142
143
144
145
146
147
148
#!/usr/bin/env python2
#
# Format a perftest text dump into a HTML table.
#
import os
import sys
import re
def main():
# test-try-catch-throw.js : duk.O2.alt0 40.70 duk.O2.alt0f 40.74 duk.O2.alt1 40.10 duk.O2.alt1a 39.91 duk.O2.alt2 40.10 duk.O2.alt3 39.77 duk.O2.master 40.01 duk.O2.130 38.08
re_line = re.compile(r'^(\S+)\s*:\s*(.*?)$')
re_part = re.compile(r'\S+')
colors = True
headings = []
testnames = []
results = []
baseline = []
# Column index (positive or negative) for baseline engine (after filtering).
baseline_column = 4
with open(sys.argv[1], 'rb') as f_in, open(sys.argv[2], 'wb') as f_out:
for line in f_in:
line = line.strip()
m = re_line.match(line)
if m is None:
continue
testname = m.group(1)
testnames.append(testname)
parts = re_part.findall(m.group(2))
if len(headings) == 0:
for idx in xrange(0, len(parts), 2):
headings.append(parts[idx])
result = []
for idx in xrange(1, len(parts), 2):
try:
result.append(float(parts[idx]))
except ValueError:
result.append(None)
results.append(result)
filter_columns = [ 3, 4, 5, 6, 7, 8, 9, 10 ]
def do_filter(val):
res = []
for i in filter_columns:
res.append(val[i])
return res
#headings = do_filter(headings)
#results = [ do_filter(x) for x in results ]
baseline = [ x[baseline_column] for x in results ]
#print(repr(headings))
#print(repr(results))
f_out.write('<!DOCTYPE html>\n')
f_out.write('<html>\n')
f_out.write('<head>\n')
f_out.write("""\
<style>
th, td { margin: 0; padding: 6pt; text-align: right; }
tr:nth-child(odd) { background: #eeeeee; }
</style>
""")
f_out.write('</head>\n')
f_out.write('<body>\n')
f_out.write('<table>\n')
f_out.write('<tr>')
f_out.write('<th></th>')
for h in headings:
f_out.write('<th>' + h + '</th>')
f_out.write('</tr>\n')
for idx,result in enumerate(results):
f_out.write('<tr>')
f_out.write('<td>' + testnames[idx] + '</td>')
for column,t in enumerate(result):
wraptag = None
wrapchars = None
icon = None
style = 'background-color: #ffffff'
if baseline[idx] is not None and baseline[idx] > 0 and t is not None:
factor = t / baseline[idx]
if factor < 0.90:
style = 'background-color: #88ff88; font-weight: bold'
wraptag = 'strong'
icon = '▲'
elif factor < 0.93:
style = 'background-color: #ddffdd'
wraptag = 'strong'
icon = '⇑'
elif factor < 0.97:
style = 'background-color: #eeffee'
elif factor > 1.10:
style = 'background-color: #ff8888; font-weight: bold'
wraptag = 'em'
wrapchars = '()'
icon = '▼'
elif factor > 1.07:
style = 'background-color: #ffdddd'
wraptag = 'em'
wrapchars = '()'
icon = '⇓'
elif factor > 1.03:
style = 'background-color: #ffeeee'
wrapchars = '()'
else:
pass
if column == baseline_column:
style = 'background-color: #eeeeee'
#if column not in [ 3, 4 ]:
# style = 'background-color: #eeeeee'
if t is None:
text = '-'
else:
text = '%.2f' % t
# style doesn't survive in GFM; em/strong does
if wrapchars is not None:
text = '%s%s%s' % (wrapchars[0], text, wrapchars[1])
if wraptag is not None:
text = '<%s>%s</%s>' % (wraptag, text, wraptag)
if icon is not None:
text = '%s %s' % (text, icon)
f_out.write('<td style="%s">%s</td>' % (style, text))
f_out.write('</tr>\n')
f_out.write('</table>\n')
f_out.write('</body>\n')
f_out.write('</html>\n')
if __name__ == '__main__':
main()