Skip to content

⚡️ Speed up function parse_log_sympy by 24% #49

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 15 additions & 15 deletions evaluation/benchmarks/testgeneval/log_parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,25 +206,25 @@ def parse_log_sympy(log: str) -> dict[str, str]:
"""
test_status_map = {}
pattern = r'(_*) (.*)\.py:(.*) (_*)'
matches = re.findall(pattern, log)
matches = re.finditer(pattern, log) # Using re.finditer for better efficiency with large logs
failed_value = TestStatus.FAILED.value # Cache the attribute access
for match in matches:
test_case = f'{match[1]}.py:{match[2]}'
test_status_map[test_case] = TestStatus.FAILED.value
for line in log.split('\n'):
test_case = f'{match.group(2)}.py:{match.group(3)}'
test_status_map[test_case] = failed_value

error_value = TestStatus.ERROR.value
passed_value = TestStatus.PASSED.value
for line in log.splitlines(): # Avoids creating a list just to loop through it
line = line.strip()
if line.startswith('test_'):
if line.endswith('[FAIL]') or line.endswith('[OK]'):
line = line[: line.rfind('[')]
line = line.strip()
if line.endswith(' E'):
test = line.split()[0]
test_status_map[test] = TestStatus.ERROR.value
if line.endswith(' F'):
test = line.split()[0]
test_status_map[test] = TestStatus.FAILED.value
if line.endswith(' ok'):
test = line.split()[0]
test_status_map[test] = TestStatus.PASSED.value
# Use line[:line.rfind(' ')] to avoid split call
test_status_map[line[:line.rfind(' ')]] = error_value
elif line.endswith(' F'):
test_status_map[line[:line.rfind(' ')]] = failed_value
elif line.endswith(' ok'):
test_status_map[line[:line.rfind(' ')]] = passed_value

return test_status_map


Expand Down