7 from optparse import OptionParser
9 parser = OptionParser(usage="%prog [options] <reference> <file2> .. <fileN>",
11 Generate reports comparing two or more outputs of expedite.
13 Just run expedite and save output to a file and then feed them to this
14 program. The first file is used as base for comparison and other files
15 will print relative improvements.
17 parser.add_option("-e", "--accepted-error",
18 help=("maximum error to accept as percentage 0.0-1.0. "
19 "[default=%default]"),
20 action="store", type="float", default=0.05)
21 parser.add_option("-r", "--report",
22 help=("kind of report to use. One of text or html. "
23 "[default=%default]"),
24 action="store", type="choice", default="text",
25 choices=["text", "html"])
26 parser.add_option("-p", "--percentual",
27 help=("show percentual instead of raw numbers for "
28 "non-reference values."),
29 action="store_true", default=False)
30 parser.add_option("-C", "--no-color", dest="color",
31 help="do not use color in reports.",
32 action="store_false", default=True)
34 options, files = parser.parse_args()
36 raise SystemExit("need at least 2 files to compare")
47 for row in csv.reader(open(f)):
52 max_test_name = max(len(t), max_test_name)
55 test_name_fmt = "%%%ds:" % max_test_name
57 print test_name_fmt % "\\",
59 n, e = os.path.splitext(f)
60 print "%7.7s" % n[-7:],
63 if options.color and os.environ.get("TERM", "") == "xterm":
64 color_good = "\033[1;32m"
65 color_bad = "\033[1;31m"
66 color_equal = "\033[1;30m"
67 color_reset = "\033[0m"
76 print test_name_fmt % test,
77 ref_val = data[ref_f][test]
78 print "%7.2f" % ref_val,
86 percent = (val - ref_val) / ref_val
87 if percent < -options.accepted_error:
89 elif percent > options.accepted_error:
94 if options.percentual:
95 print "%s%+6.1f%%%s" % (c, (percent * 100), color_reset),
97 print "%s%7.2f%s" % (c, val, color_reset),
108 fnames = [os.path.basename(f) for f in files]
110 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
111 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
113 <html xmlns="http://www.w3.org/1999/xhtml">
115 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
116 <title>expedite comparison sheet: %(files)s</title>
118 <style type="text/css">
119 td.value, td.value-reference, td.value-missing, td.value-good, td.value-bad, td.value-equal
121 font-family: courier, monospaced;
125 td.test-name, thead tr td { text-align: right; }\
129 td.value-good { background-color: #aaffaa; }
130 td.value-bad { background-color: #ffaaaa; }
131 td.value-missing { background-color: #ffffaa; }
132 td.test-name, thead tr td
135 background-color: #d9d9d9;
142 <p>Comparison sheet for %(files)s, created at %(date)s.</p>
147 """ % {"files": ", ".join(fnames),
148 "date": time.asctime(),
162 ref_val = data[ref_f][test]
165 <td class="test-name">%s</td>
166 <td class="value-reference">%7.2f</td>\
167 """ % (test, ref_val)
174 <td class="value-missing">-?????-</td>\
178 percent = (val - ref_val) / ref_val
179 if percent < -options.accepted_error:
181 elif percent > options.accepted_error:
186 if options.percentual:
187 v = "%+6.1f%%" % (percent * 100)
192 <td class="value-%s">%s</td>\
209 if options.report == "text":
211 elif options.report == "html":