8484from codeflash .verification .equivalence import compare_test_results
8585from codeflash .verification .instrument_codeflash_capture import instrument_codeflash_capture
8686from codeflash .verification .parse_line_profile_test_output import parse_line_profile_results
87- from codeflash .verification .parse_test_output import parse_test_results
87+ from codeflash .verification .parse_test_output import calculate_function_throughput_from_stdout , parse_test_results
8888from codeflash .verification .test_runner import run_behavioral_tests , run_benchmarking_tests , run_line_profile_tests
8989from codeflash .verification .verification_utils import get_test_file_path
9090from codeflash .verification .verifier import generate_tests
@@ -1388,7 +1388,7 @@ def establish_original_code_baseline(
13881388 instrument_codeflash_capture (
13891389 self .function_to_optimize , file_path_to_helper_classes , self .test_cfg .tests_root
13901390 )
1391- behavioral_results , coverage_results , behavioral_test_results_for_throughput = self .run_and_parse_tests (
1391+ behavioral_results , coverage_results , _ = self .run_and_parse_tests (
13921392 testing_type = TestingMode .BEHAVIOR ,
13931393 test_env = test_env ,
13941394 test_files = self .test_files ,
@@ -1409,7 +1409,6 @@ def establish_original_code_baseline(
14091409 return Failure ("Failed to establish a baseline for the original code - bevhavioral tests failed." )
14101410 if not coverage_critic (coverage_results , self .args .test_framework ):
14111411 return Failure ("The threshold for test coverage was not met." )
1412- benchmarking_test_results_for_throughput = None
14131412
14141413 if test_framework == "pytest" :
14151414 line_profile_results = self .line_profiler_step (
@@ -1433,7 +1432,7 @@ def establish_original_code_baseline(
14331432 )
14341433
14351434 try :
1436- benchmarking_results , _ , benchmarking_test_results_for_throughput = self .run_and_parse_tests (
1435+ benchmarking_results , _ , _ = self .run_and_parse_tests (
14371436 testing_type = TestingMode .PERFORMANCE ,
14381437 test_env = test_env ,
14391438 test_files = self .test_files ,
@@ -1504,9 +1503,17 @@ def establish_original_code_baseline(
15041503 console .rule ()
15051504 logger .debug (f"Total original code runtime (ns): { total_timing } " )
15061505
1507- async_throughput = self .calculate_async_throughput (
1508- behavioral_test_results_for_throughput , benchmarking_test_results_for_throughput
1509- )
1506+ async_throughput = None
1507+ if self .function_to_optimize .is_async and benchmarking_results :
1508+ all_stdout = ""
1509+ for result in benchmarking_results .test_results :
1510+ if result .stdout :
1511+ all_stdout += result .stdout
1512+
1513+ if all_stdout :
1514+ async_throughput = calculate_function_throughput_from_stdout (
1515+ all_stdout , self .function_to_optimize .function_name
1516+ )
15101517
15111518 if self .args .benchmark :
15121519 replay_benchmarking_test_results = benchmarking_results .group_by_benchmarks (
@@ -1776,8 +1783,7 @@ def run_and_parse_tests(
17761783 coverage_database_file = coverage_database_file ,
17771784 coverage_config_file = coverage_config_file ,
17781785 )
1779- # Return the test results for async throughput calculation
1780- return results , coverage_results , results if isinstance (results , TestResults ) else None
1786+ return results , coverage_results , None
17811787 results , coverage_results = parse_line_profile_results (line_profiler_output_file = line_profiler_output_file )
17821788 return results , coverage_results , None
17831789
@@ -1830,31 +1836,6 @@ def get_test_env(
18301836 test_env ["PYTHONPATH" ] += os .pathsep + str (self .args .project_root )
18311837 return test_env
18321838
1833- def calculate_async_throughput (
1834- self , behavioral_test_results : TestResults | None , benchmarking_test_results : TestResults | None
1835- ) -> dict [str , int ] | None :
1836- if not self .function_to_optimize .is_async :
1837- return None
1838-
1839- from codeflash .verification .parse_test_output import calculate_function_throughput_from_stdout
1840-
1841- all_stdout = ""
1842-
1843- for test_results in [behavioral_test_results , benchmarking_test_results ]:
1844- if test_results :
1845- for result in test_results .test_results :
1846- if result .stdout :
1847- all_stdout += result .stdout
1848-
1849- if not all_stdout :
1850- return None
1851-
1852- function_throughput = calculate_function_throughput_from_stdout (
1853- all_stdout , self .function_to_optimize .function_name
1854- )
1855-
1856- return {self .function_to_optimize .function_name : function_throughput } if function_throughput > 0 else None
1857-
18581839 def line_profiler_step (
18591840 self , code_context : CodeOptimizationContext , original_helper_code : dict [Path , str ], candidate_index : int
18601841 ) -> dict :
0 commit comments