From 5cca6235e1ce04f24eb8476026147bad5b1118b8 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 20 Nov 2025 23:26:36 +0000 Subject: [PATCH] Fix potential division by zero in performance tests Co-authored-by: denizsafak <39929354+denizsafak@users.noreply.github.com> --- test_performance.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/test_performance.py b/test_performance.py index 6f735ef..76531d3 100644 --- a/test_performance.py +++ b/test_performance.py @@ -52,6 +52,10 @@ def test_regex_precompilation_performance(): # Verify results are the same assert old_way(test_text) == new_way(test_text), "Results should be identical" + # Guard against division by zero (though very unlikely with 1000 iterations) + elapsed_old = max(elapsed_old, 0.000001) + elapsed_new = max(elapsed_new, 0.000001) + improvement = ((elapsed_old - elapsed_new) / elapsed_old) * 100 print(f" Old way (non-compiled): {elapsed_old:.4f} seconds") @@ -105,6 +109,10 @@ def test_clean_text_performance(): # Verify results are the same assert old_clean_text(test_text) == new_clean_text(test_text), "Results should be identical" + # Guard against division by zero + elapsed_old = max(elapsed_old, 0.000001) + elapsed_new = max(elapsed_new, 0.000001) + improvement = ((elapsed_old - elapsed_new) / elapsed_old) * 100 print(f" Old way (non-compiled): {elapsed_old:.4f} seconds") @@ -166,6 +174,10 @@ def test_pdf_text_cleaning_performance(): # Verify results are the same assert old_way(test_text) == new_way(test_text), "Results should be identical" + # Guard against division by zero + elapsed_old = max(elapsed_old, 0.000001) + elapsed_new = max(elapsed_new, 0.000001) + improvement = ((elapsed_old - elapsed_new) / elapsed_old) * 100 print(f" Old way (non-compiled): {elapsed_old:.4f} seconds")