Skip to content

Commit 2e0f38f

Browse files
committed
throughput
1 parent a947ea0 commit 2e0f38f

File tree

2 files changed

+16
-25
lines changed

2 files changed

+16
-25
lines changed

codeflash/optimization/function_optimizer.py

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@
9090
from codeflash.verification.equivalence import compare_test_results
9191
from codeflash.verification.instrument_codeflash_capture import instrument_codeflash_capture
9292
from codeflash.verification.parse_line_profile_test_output import parse_line_profile_results
93-
from codeflash.verification.parse_test_output import calculate_function_throughput_from_stdout, parse_test_results
93+
from codeflash.verification.parse_test_output import calculate_function_throughput_from_test_results, parse_test_results
9494
from codeflash.verification.test_runner import run_behavioral_tests, run_benchmarking_tests, run_line_profile_tests
9595
from codeflash.verification.verification_utils import get_test_file_path
9696
from codeflash.verification.verifier import generate_tests
@@ -1528,14 +1528,9 @@ def establish_original_code_baseline(
15281528

15291529
async_throughput = None
15301530
if self.function_to_optimize.is_async:
1531-
all_stdout = ""
1532-
for result in benchmarking_results.test_results:
1533-
if result.stdout:
1534-
all_stdout += result.stdout
15351531
logger.info("Calculating async function throughput from test output...")
1536-
logger.info(f"All stdout for async throughput calculation:\n{all_stdout}")
1537-
async_throughput = calculate_function_throughput_from_stdout(
1538-
all_stdout, self.function_to_optimize.function_name
1532+
async_throughput = calculate_function_throughput_from_test_results(
1533+
benchmarking_results, self.function_to_optimize.function_name
15391534
)
15401535
logger.info(f"Original async function throughput: {async_throughput} calls/second")
15411536

@@ -1700,13 +1695,8 @@ def run_optimized_candidate(
17001695

17011696
candidate_async_throughput = None
17021697
if self.function_to_optimize.is_async and candidate_benchmarking_results:
1703-
all_stdout = ""
1704-
for result in candidate_benchmarking_results.test_results:
1705-
if result.stdout:
1706-
all_stdout += result.stdout
1707-
1708-
candidate_async_throughput = calculate_function_throughput_from_stdout(
1709-
all_stdout, self.function_to_optimize.function_name
1698+
candidate_async_throughput = calculate_function_throughput_from_test_results(
1699+
candidate_benchmarking_results, self.function_to_optimize.function_name
17101700
)
17111701

17121702
if self.args.benchmark:

codeflash/verification/parse_test_output.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,26 +44,27 @@ def parse_func(file_path: Path) -> XMLParser:
4444
end_pattern = re.compile(r"!######([^:]*):([^:]*):([^:]*):([^:]*):([^:]+)######!")
4545

4646

47-
def calculate_function_throughput_from_stdout(stdout: str, function_name: str) -> int:
48-
"""Calculate function throughput from stdout. A completed execution is defined as having both a start tag and matching end tag.
47+
def calculate_function_throughput_from_test_results(test_results: TestResults, function_name: str) -> int:
48+
"""Calculate function throughput from TestResults by extracting stdout.
4949
50+
A completed execution is defined as having both a start tag and matching end tag.
5051
Start: !$######test_module:test_function:function_name:loop_index:iteration_id######$!
5152
End: !######test_module:test_function:function_name:loop_index:iteration_id######!
5253
"""
53-
start_matches = start_pattern.findall(stdout)
54-
end_matches = end_pattern.findall(stdout)
54+
all_stdout = ""
55+
for result in test_results.test_results:
56+
if result.stdout:
57+
all_stdout += result.stdout
58+
59+
start_matches = start_pattern.findall(all_stdout)
60+
end_matches = end_pattern.findall(all_stdout)
5561
end_matches_set = set(end_matches)
5662

57-
# Count completed executions for the specific function only
5863
function_throughput = 0
5964
logger.info(f"Total start matches: {len(start_matches)}, Total end matches: {len(end_matches)}")
6065
for start_match in start_matches:
61-
# Check if this execution is for the function we're interested in and has a matching end tag
62-
# function_name is at index 2 in the match tuple
63-
logger.info(f"Start match: {start_match}")
64-
logger.info(f"End matches: {end_matches_set}")
65-
logger.info(f"Function name: {function_name}")
6666
if start_match in end_matches_set and len(start_match) > 2 and start_match[2] == function_name:
67+
logger.info(f"Matched start-end pair for function '{function_name}': {start_match}")
6768
function_throughput += 1
6869

6970
return function_throughput

0 commit comments

Comments
 (0)