|
| 1 | +import sys |
| 2 | + |
| 3 | +def parse_results(filename): |
| 4 | + results = {} |
| 5 | + fd = open(filename, 'r') |
| 6 | + section = "???" |
| 7 | + for line in fd.readlines(): |
| 8 | + line = line.strip() |
| 9 | + if line.startswith("testing"): |
| 10 | + section = line.split(" ", 1)[1] |
| 11 | + results.setdefault(section, {}) |
| 12 | + elif line.startswith("driving"): |
| 13 | + driving, test, time = [x.strip() for x in line.split()] |
| 14 | + time = float(time) |
| 15 | + results[section][test] = time |
| 16 | + fd.close() |
| 17 | + return results |
| 18 | + |
| 19 | + |
| 20 | +def check_results_are_compatible(results_a, results_b): |
| 21 | + for section in results_a.keys(): |
| 22 | + if not section in results_b: |
| 23 | + raise RuntimeError("Backend '%s' in first set, but not in second" % section) |
| 24 | + |
| 25 | + for section in results_b.keys(): |
| 26 | + if not section in results_a: |
| 27 | + raise RuntimeError("Backend '%s' in second set, but not in first" % section) |
| 28 | + |
| 29 | + |
| 30 | +def compare_results(results_a, results_b): |
| 31 | + check_results_are_compatible(results_a, results_b) |
| 32 | + |
| 33 | + sections = results_a.keys() |
| 34 | + sections.sort() |
| 35 | + for section in results_a.keys(): |
| 36 | + print "backend %s" % section |
| 37 | + print " %-40s %6s %6s %6s %6s" % ("test", "a", "b", "delta", "% diff") |
| 38 | + print " " + '-' * 69 |
| 39 | + deltas = [] |
| 40 | + section_a = results_a[section] |
| 41 | + section_b = results_b[section] |
| 42 | + for test in section_a.keys(): |
| 43 | + if test not in section_b: |
| 44 | + deltas.append([None, None, section_a[test], None, test]) |
| 45 | + else: |
| 46 | + time_a = section_a[test] |
| 47 | + time_b = section_b[test] |
| 48 | + deltas.append([time_b / time_a, time_b - time_a, time_a, time_b, test]) |
| 49 | + for test in section_b.keys(): |
| 50 | + if test not in section_a: |
| 51 | + deltas.append([None, None, None, section_b[test], test]) |
| 52 | + |
| 53 | + deltas.sort() |
| 54 | + for diff, delta, time_a, time_b, test in deltas: |
| 55 | + if diff is None: |
| 56 | + if time_a is None: |
| 57 | + print " %-40s ??? % 6.3f ??? ???" % (test, time_b) |
| 58 | + else: |
| 59 | + print " %-40s % 6.3f ??? ??? ???" % (test, time_a) |
| 60 | + else: |
| 61 | + print " %-40s % 6.3f % 6.3f % 6.3f %6d%%" % (test, time_a, time_b, delta, diff * 100) |
| 62 | + |
| 63 | + |
| 64 | +if __name__ == '__main__': |
| 65 | + results_a_filename = sys.argv[-2] |
| 66 | + results_b_filename = sys.argv[-1] |
| 67 | + |
| 68 | + results_a = parse_results(results_a_filename) |
| 69 | + results_b = parse_results(results_b_filename) |
| 70 | + |
| 71 | + compare_results(results_a, results_b) |
0 commit comments