diff --git a/codeflash/code_utils/time_utils.py b/codeflash/code_utils/time_utils.py index d62c750cf..ad3b5f642 100644 --- a/codeflash/code_utils/time_utils.py +++ b/codeflash/code_utils/time_utils.py @@ -24,11 +24,14 @@ 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 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/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." diff --git a/tests/test_humanize_time.py b/tests/test_humanize_time.py index c16033ad1..608c66b10 100644 --- a/tests/test_humanize_time.py +++ b/tests/test_humanize_time.py @@ -8,20 +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 days" + assert humanize_runtime(197530862597520) == "2.29 days"