Skip to content

Commit 71b38d5

Browse files
fix: Parse timing markers from console output for JavaScript benchmarking
The _parse_timing_from_jest_output() function was defined but never called, causing benchmarking tests to report runtime=0. This integrates console timing marker parsing into parse_test_results() to extract accurate performance data from capturePerf() calls. Fixes the "summed benchmark runtime of the original function is 0" error when timing data exists in console output but JUnit XML reports 0.
1 parent 017bde1 commit 71b38d5

1 file changed

Lines changed: 27 additions & 3 deletions

File tree

codeflash/languages/javascript/support.py

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1533,6 +1533,11 @@ def parse_test_results(self, junit_xml_path: Path, stdout: str) -> list[TestResu
15331533
if not junit_xml_path.exists():
15341534
return results
15351535

1536+
# Parse timing markers from console output (for performance tests)
1537+
from codeflash.languages.javascript.test_runner import _parse_timing_from_jest_output
1538+
1539+
timing_from_console = _parse_timing_from_jest_output(stdout)
1540+
15361541
try:
15371542
tree = ET.parse(junit_xml_path)
15381543
root = tree.getroot()
@@ -1542,11 +1547,30 @@ def parse_test_results(self, junit_xml_path: Path, stdout: str) -> list[TestResu
15421547
classname = testcase.get("classname", "")
15431548
time_str = testcase.get("time", "0")
15441549

1545-
# Convert time to nanoseconds
1550+
# Convert time to nanoseconds from XML
15461551
try:
1547-
runtime_ns = int(float(time_str) * 1_000_000_000)
1552+
runtime_ns_xml = int(float(time_str) * 1_000_000_000)
15481553
except ValueError:
1549-
runtime_ns = None
1554+
runtime_ns_xml = None
1555+
1556+
# Try to get more accurate timing from console markers (for performance tests)
1557+
# The console markers are more accurate than JUnit XML time for benchmarking
1558+
runtime_ns = runtime_ns_xml
1559+
if timing_from_console:
1560+
# Try to match this test case to timing data from console
1561+
# Console timing uses format: module:testClass:funcName:invocationId
1562+
# We need to find matching entries
1563+
for timing_key, timing_value in timing_from_console.items():
1564+
# timing_key format: "module:testClass:funcName:invocationId"
1565+
# Check if this timing entry matches the current test
1566+
if name in timing_key or classname in timing_key:
1567+
# Use console timing if it's non-zero and looks more accurate
1568+
if timing_value > 0:
1569+
runtime_ns = timing_value
1570+
logger.debug(
1571+
f"Using console timing for {name}: {timing_value}ns (XML had {runtime_ns_xml}ns)"
1572+
)
1573+
break
15501574

15511575
# Check for failure/error
15521576
failure = testcase.find("failure")

0 commit comments

Comments
 (0)