From 5443f515963e2b388f5a70778c38c2c562747a7e Mon Sep 17 00:00:00 2001 From: aseembits93 Date: Tue, 13 May 2025 14:07:54 -0700 Subject: [PATCH 1/2] doing in a single loop now --- codeflash/models/models.py | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/codeflash/models/models.py b/codeflash/models/models.py index 38d1f4db0..35f9697af 100644 --- a/codeflash/models/models.py +++ b/codeflash/models/models.py @@ -537,22 +537,19 @@ def report_to_tree(report: dict[TestType, dict[str, int]], title: str) -> Tree: return tree def usable_runtime_data_by_test_case(self) -> dict[InvocationId, list[int]]: + usable_id_to_runtime = defaultdict(list) for result in self.test_results: - if result.did_pass and not result.runtime: - msg = ( - f"Ignoring test case that passed but had no runtime -> {result.id}, " - f"Loop # {result.loop_index}, Test Type: {result.test_type}, " - f"Verification Type: {result.verification_type}" - ) - logger.debug(msg) - - usable_runtimes = [ - (result.id, result.runtime) for result in self.test_results if result.did_pass and result.runtime - ] - return { - usable_id: [runtime[1] for runtime in usable_runtimes if runtime[0] == usable_id] - for usable_id in {runtime[0] for runtime in usable_runtimes} - } + if result.did_pass: + if not result.runtime: + msg = ( + f"Ignoring test case that passed but had no runtime -> {result.id}, " + f"Loop # {result.loop_index}, Test Type: {result.test_type}, " + f"Verification Type: {result.verification_type}" + ) + logger.debug(msg) + else: + usable_id_to_runtime[result.id].append(result.runtime) + return usable_id_to_runtime def total_passed_runtime(self) -> int: """Calculate the sum of runtimes of all test cases that passed. From f2148e2f89f1e3c467408239a8391a4b3f822b5a Mon Sep 17 00:00:00 2001 From: aseembits93 Date: Tue, 13 May 2025 14:25:19 -0700 Subject: [PATCH 2/2] trying codeflash version --- codeflash/models/models.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/codeflash/models/models.py b/codeflash/models/models.py index 35f9697af..32add0a94 100644 --- a/codeflash/models/models.py +++ b/codeflash/models/models.py @@ -537,19 +537,20 @@ def report_to_tree(report: dict[TestType, dict[str, int]], title: str) -> Tree: return tree def usable_runtime_data_by_test_case(self) -> dict[InvocationId, list[int]]: - usable_id_to_runtime = defaultdict(list) + # Efficient single traversal, directly accumulating into a dict. + by_id: dict[InvocationId, list[int]] = {} for result in self.test_results: if result.did_pass: - if not result.runtime: + if result.runtime: + by_id.setdefault(result.id, []).append(result.runtime) + else: msg = ( f"Ignoring test case that passed but had no runtime -> {result.id}, " f"Loop # {result.loop_index}, Test Type: {result.test_type}, " f"Verification Type: {result.verification_type}" ) logger.debug(msg) - else: - usable_id_to_runtime[result.id].append(result.runtime) - return usable_id_to_runtime + return by_id def total_passed_runtime(self) -> int: """Calculate the sum of runtimes of all test cases that passed.