1818)
1919from codeflash .code_utils .github_utils import github_pr_url
2020from codeflash .code_utils .tabulate import tabulate
21- from codeflash .code_utils .time_utils import format_time
21+ from codeflash .code_utils .time_utils import format_perf , format_time
2222from codeflash .github .PrComment import FileDiffContent , PrComment
2323from codeflash .result .critic import performance_gain
2424
@@ -40,7 +40,7 @@ def existing_tests_source_for(
4040 return ""
4141 output : str = ""
4242 rows = []
43- headers = ["Test File::Test Function" , "Original ⏱️" , "Optimized ⏱️" , "Improvement " ]
43+ headers = ["Test File::Test Function" , "Original ⏱️" , "Optimized ⏱️" , "Speedup " ]
4444 tests_root = test_cfg .tests_root
4545 module_root = test_cfg .project_root_path
4646 rel_tests_root = tests_root .relative_to (module_root )
@@ -84,23 +84,17 @@ def existing_tests_source_for(
8484 ].keys () # both will have the same keys as some default values are assigned in the previous loop
8585 for qualified_name in sorted (all_qualified_names ):
8686 # if not present in optimized output nan
87- if optimized_tests_to_runtimes [filename ][qualified_name ] == 0 :
88- print_optimized_runtime = "NaN"
89- else :
90- print_optimized_runtime = format_time (optimized_tests_to_runtimes [filename ][qualified_name ])
91- if original_tests_to_runtimes [filename ][qualified_name ] == 0 :
92- print_original_runtime = "NaN"
93- else :
94- print_original_runtime = format_time (original_tests_to_runtimes [filename ][qualified_name ])
9587 if (
9688 original_tests_to_runtimes [filename ][qualified_name ] != 0
9789 and optimized_tests_to_runtimes [filename ][qualified_name ] != 0
9890 ):
91+ print_optimized_runtime = format_time (optimized_tests_to_runtimes [filename ][qualified_name ])
92+ print_original_runtime = format_time (original_tests_to_runtimes [filename ][qualified_name ])
9993 greater = (
10094 optimized_tests_to_runtimes [filename ][qualified_name ]
10195 > original_tests_to_runtimes [filename ][qualified_name ]
10296 )
103- perf_gain = (
97+ perf_gain = format_perf (
10498 performance_gain (
10599 original_runtime_ns = original_tests_to_runtimes [filename ][qualified_name ],
106100 optimized_runtime_ns = optimized_tests_to_runtimes [filename ][qualified_name ],
@@ -113,7 +107,7 @@ def existing_tests_source_for(
113107 f"`{ filename } ::{ qualified_name } `" ,
114108 f"{ print_original_runtime } " ,
115109 f"{ print_optimized_runtime } " ,
116- f"⚠️{ perf_gain :.2f } %" ,
110+ f"⚠️{ perf_gain } %" ,
117111 ]
118112 )
119113 else :
@@ -122,14 +116,9 @@ def existing_tests_source_for(
122116 f"`{ filename } ::{ qualified_name } `" ,
123117 f"{ print_original_runtime } " ,
124118 f"{ print_optimized_runtime } " ,
125- f"✅{ perf_gain :.2f } %" ,
119+ f"✅{ perf_gain } %" ,
126120 ]
127121 )
128- else :
129- # one of them is NaN
130- rows .append (
131- [f"`{ filename } ::{ qualified_name } `" , f"{ print_original_runtime } " , f"{ print_optimized_runtime } " , "❌" ]
132- )
133122 output += tabulate ( # type: ignore[no-untyped-call]
134123 headers = headers , tabular_data = rows , tablefmt = "pipe" , colglobalalign = None , preserve_whitespace = True
135124 )
0 commit comments