clerk/.github/scripts/check-bench-regression.py (view raw)
| 1 | #!/usr/bin/env python3 |
| 2 | """Fail if any benchmark regressed beyond the threshold. |
| 3 | |
| 4 | Reads benchstat CSV comparison (old vs new) from stdin. benchstat only |
| 5 | reports a numeric delta for statistically significant changes (p < 0.05); |
| 6 | noisy comparisons are marked "~" and ignored. |
| 7 | """ |
| 8 | import csv |
| 9 | import sys |
| 10 | |
| 11 | THRESHOLD = 20.0 # percent slower |
| 12 | |
| 13 | def delta_pct(s): |
| 14 | s = s.strip() |
| 15 | if not s or s == "~": |
| 16 | return None |
| 17 | sign = 1.0 |
| 18 | if s.startswith("+"): |
| 19 | s = s[1:] |
| 20 | elif s.startswith("-"): |
| 21 | sign = -1.0 |
| 22 | s = s[1:] |
| 23 | s = s.rstrip("%") |
| 24 | if s in ("∞", "Inf", "inf", "+Inf"): |
| 25 | return sign * float("inf") |
| 26 | try: |
| 27 | return sign * float(s) |
| 28 | except ValueError: |
| 29 | return None |
| 30 | |
| 31 | def main(): |
| 32 | regressions = [] |
| 33 | for row in csv.reader(sys.stdin): |
| 34 | if len(row) < 7 or row[0] in ("", "geomean"): |
| 35 | continue |
| 36 | d = delta_pct(row[5]) # vs base column |
| 37 | if d is not None and d > THRESHOLD: |
| 38 | regressions.append((row[0], d)) |
| 39 | |
| 40 | if not regressions: |
| 41 | print("no regressions beyond +%.0f%%" % THRESHOLD) |
| 42 | return 0 |
| 43 | |
| 44 | print("performance regressions beyond +%.0f%%:" % THRESHOLD) |
| 45 | for name, d in sorted(regressions): |
| 46 | if d == float("inf"): |
| 47 | print(" %s: +∞ (new cost where none before)" % name) |
| 48 | else: |
| 49 | print(" %s: +%.1f%%" % (name, d)) |
| 50 | return 1 |
| 51 | |
| 52 | |
| 53 | if __name__ == "__main__": |
| 54 | sys.exit(main()) |