31 lines
1.3 KiB
Python
31 lines
1.3 KiB
Python
"""Compare two outputs of bench/regression.py: print the station/family lines that changed, flagging a regression (found or correct down by more than 2 points). Usage: python3 bench_diff.py BEFORE.txt AFTER.txt"""
|
|
import re
|
|
import sys
|
|
|
|
|
|
def parse(path):
|
|
out, station = {}, None
|
|
for line in open(path, encoding="utf-8"):
|
|
if line and not line.startswith(" ") and line.strip():
|
|
station = line.split(":")[0].strip()
|
|
continue
|
|
m = re.match(r"\s+(\S.*?)\s{2,}(\S+(?: \(\d+ %\))?|—)\s+(\S+(?: \(\d+ %\))?|—)\s*$", line)
|
|
if m and m.group(1) != "found":
|
|
out[(station, m.group(1))] = (m.group(2), m.group(3))
|
|
return out
|
|
|
|
|
|
def pct(x):
|
|
m = re.match(r"(\d+)/(\d+)", x)
|
|
return 100 * int(m.group(1)) / int(m.group(2)) if m and int(m.group(2)) else None
|
|
|
|
|
|
a, b = parse(sys.argv[1]), parse(sys.argv[2])
|
|
for k in sorted(set(a) | set(b)):
|
|
va, vb = a.get(k, ("—", "—")), b.get(k, ("—", "—"))
|
|
if va != vb:
|
|
reg = [n for n, x, y in zip(("found", "correct"), va, vb)
|
|
if pct(x) is not None and pct(y) is not None and pct(y) < pct(x) - 2]
|
|
print(f"{k[0]:<12} {k[1]:<22} found {va[0]} → {vb[0]} | correct {va[1]} → {vb[1]}",
|
|
"REGRESSION " + ",".join(reg) if reg else "")
|