From 5f9bf526bed745fe4c99dd5090b318b878d2f242 Mon Sep 17 00:00:00 2001 From: Aseem Saxena Date: Sun, 18 May 2025 16:49:40 -0400 Subject: [PATCH 1/3] handle days --- codeflash/code_utils/time_utils.py | 5 +++-- tests/test_humanize_time.py | 2 ++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/codeflash/code_utils/time_utils.py b/codeflash/code_utils/time_utils.py index d62c750cf..92ea26edd 100644 --- a/codeflash/code_utils/time_utils.py +++ b/codeflash/code_utils/time_utils.py @@ -24,9 +24,10 @@ def humanize_runtime(time_in_ns: int) -> str: runtime_human = "%.3g" % (time_micro / (1000**2)) elif units in {"minutes", "minute"}: runtime_human = "%.3g" % (time_micro / (60 * 1000**2)) - else: # hours + elif units in {"hour", "hours"}: #hours runtime_human = "%.3g" % (time_micro / (3600 * 1000**2)) - + else: #days + runtime_human = "%.3g" % (time_micro / (24*3600 * 1000**2)) runtime_human_parts = str(runtime_human).split(".") if len(runtime_human_parts[0]) == 1: if len(runtime_human_parts) == 1: diff --git a/tests/test_humanize_time.py b/tests/test_humanize_time.py index c16033ad1..99077ff4a 100644 --- a/tests/test_humanize_time.py +++ b/tests/test_humanize_time.py @@ -25,3 +25,5 @@ def test_humanize_runtime(): assert humanize_runtime(123456789123) == "2.06 minutes" assert humanize_runtime(1234567891234) == "20.6 minutes" assert humanize_runtime(12345678912345) == "3.43 hours" + assert humanize_runtime(98765431298760) == "1.14 day" + assert humanize_runtime(197530862597520) == "2.29 days" From 08884b210e12ecdcb51ae2d3647f8d677b145b47 Mon Sep 17 00:00:00 2001 From: Aseem Saxena Date: Sun, 18 May 2025 17:15:43 -0400 Subject: [PATCH 2/3] fixed tests to match English grammar --- codeflash/code_utils/time_utils.py | 2 ++ tests/test_humanize_time.py | 9 +++++---- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/codeflash/code_utils/time_utils.py b/codeflash/code_utils/time_utils.py index 92ea26edd..ad3b5f642 100644 --- a/codeflash/code_utils/time_utils.py +++ b/codeflash/code_utils/time_utils.py @@ -30,6 +30,8 @@ def humanize_runtime(time_in_ns: int) -> str: runtime_human = "%.3g" % (time_micro / (24*3600 * 1000**2)) runtime_human_parts = str(runtime_human).split(".") if len(runtime_human_parts[0]) == 1: + if runtime_human_parts[0]=='1' and len(runtime_human_parts)>1: + units = units+'s' if len(runtime_human_parts) == 1: runtime_human = f"{runtime_human_parts[0]}.00" elif len(runtime_human_parts[1]) >= 2: diff --git a/tests/test_humanize_time.py b/tests/test_humanize_time.py index 99077ff4a..608c66b10 100644 --- a/tests/test_humanize_time.py +++ b/tests/test_humanize_time.py @@ -8,22 +8,23 @@ def test_humanize_runtime(): assert humanize_runtime(1000000000) == "1.00 second" assert humanize_runtime(60000000000) == "1.00 minute" assert humanize_runtime(3600000000000) == "1.00 hour" + assert humanize_runtime(86400000000000) == "1.00 day" assert humanize_runtime(1) == "1.00 nanosecond" assert humanize_runtime(12) == "12.0 nanoseconds" assert humanize_runtime(123) == "123 nanoseconds" assert humanize_runtime(999) == "999 nanoseconds" - assert humanize_runtime(1234) == "1.23 microsecond" + assert humanize_runtime(1234) == "1.23 microseconds" assert humanize_runtime(12345) == "12.3 microseconds" assert humanize_runtime(123456) == "123 microseconds" - assert humanize_runtime(1234567) == "1.23 millisecond" + assert humanize_runtime(1234567) == "1.23 milliseconds" assert humanize_runtime(12345678) == "12.3 milliseconds" assert humanize_runtime(123456789) == "123 milliseconds" - assert humanize_runtime(1234567891) == "1.23 second" + assert humanize_runtime(1234567891) == "1.23 seconds" assert humanize_runtime(12345678912) == "12.3 seconds" assert humanize_runtime(123456789123) == "2.06 minutes" assert humanize_runtime(1234567891234) == "20.6 minutes" assert humanize_runtime(12345678912345) == "3.43 hours" - assert humanize_runtime(98765431298760) == "1.14 day" + assert humanize_runtime(98765431298760) == "1.14 days" assert humanize_runtime(197530862597520) == "2.29 days" From 755f02cf92785376ab119f5f3c4cd368d13100a6 Mon Sep 17 00:00:00 2001 From: Aseem Saxena Date: Sun, 18 May 2025 17:25:10 -0400 Subject: [PATCH 3/3] console.rule() --- codeflash/discovery/functions_to_optimize.py | 1 + 1 file changed, 1 insertion(+) diff --git a/codeflash/discovery/functions_to_optimize.py b/codeflash/discovery/functions_to_optimize.py index b88c4f9c9..8f5ba65eb 100644 --- a/codeflash/discovery/functions_to_optimize.py +++ b/codeflash/discovery/functions_to_optimize.py @@ -206,6 +206,7 @@ def get_functions_to_optimize( logger.info(f"Found {functions_count} function{'s' if functions_count > 1 else ''} to optimize") if optimize_all: three_min_in_ns = int(1.8e11) + console.rule() logger.info( f"It might take about {humanize_runtime(functions_count*three_min_in_ns)} to fully optimize this project. Codeflash " f"will keep opening pull requests as it finds optimizations."