[Git][ghc/ghc][wip/perf-notes-fixes] testsuite: Handle division-by-zero more gracefully

Matthew Pickering (@mpickering) gitlab at gitlab.haskell.org
Wed Oct 2 12:12:43 UTC 2024



Matthew Pickering pushed to branch wip/perf-notes-fixes at Glasgow Haskell Compiler / GHC


Commits:
de619142 by Ben Gamari at 2024-10-02T13:12:34+01:00
testsuite: Handle division-by-zero more gracefully

Previously we would fail with an ZeroDivisionError.

Fixes #25321

- - - - -


2 changed files:

- testsuite/driver/perf_notes.py
- testsuite/driver/runtests.py


Changes:

=====================================
testsuite/driver/perf_notes.py
=====================================
@@ -665,7 +665,10 @@ def check_stats_change(actual: PerfStat,
         display('    Upper bound ' + full_name + ' ' + actual.metric + ':', upperBound, '')
         display('    Actual      ' + full_name + ' ' + actual.metric + ':', actual.value, '')
         if actual.value != expected_val:
-            actual_dev = round(((float(actual.value) * 100)/ int(expected_val)) - 100, 1)
+            if expected_val == 0:
+                actual_dev = 100.0
+            else:
+                actual_dev = round(((float(actual.value) * 100)/ int(expected_val)) - 100, 1)
             display('    Deviation   ' + full_name + ' ' + actual.metric + ':', actual_dev, '%')
 
     return (change, result)


=====================================
testsuite/driver/runtests.py
=====================================
@@ -404,7 +404,12 @@ def tabulate_metrics(metrics: List[PerfMetric]) -> None:
             return ""
         val0 = x.baseline.perfStat.value
         val1 = x.stat.value
-        return "{:+2.1f}%".format(100 * (val1 - val0) / val0)
+        if val0 == 0 and val1 == 0:
+            return "0.0%"
+        elif val0 == 0:
+            return "NaN%"
+        else:
+            return "{:+2.1f}%".format(100 * (val1 - val0) / val0)
     dataRows = [row((
         "{}({})".format(x.stat.test, x.stat.way),
         shorten_metric_name(x.stat.metric),
@@ -425,6 +430,7 @@ def tabulate_metrics(metrics: List[PerfMetric]) -> None:
         x.stat.value / x.baseline.perfStat.value
         for x in metrics
         if x.baseline is not None
+        if x.baseline.perfStat.value != 0
     ]
     minimum = 0.0
     maximum = 0.0



View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/de619142bd8fd8f71d40641e6d7572866e09adab

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/de619142bd8fd8f71d40641e6d7572866e09adab
You're receiving this email because of your account on gitlab.haskell.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-commits/attachments/20241002/035985d3/attachment-0001.html>


More information about the ghc-commits mailing list