Skip to content

Commit 36b9c75

Browse files
committed
non zero runtimes for comments
1 parent 4806815 commit 36b9c75

File tree

1 file changed

+16
-14
lines changed

1 file changed

+16
-14
lines changed

codeflash/code_utils/edit_generated_tests.py

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -131,20 +131,22 @@ def leave_SimpleStatementLine(
131131
if matching_original_times and matching_optimized_times:
132132
original_time = min(matching_original_times)
133133
optimized_time = min(matching_optimized_times)
134-
perf_gain = format_perf(
135-
performance_gain(original_runtime_ns=original_time, optimized_runtime_ns=optimized_time) * 100
136-
)
137-
# Create the runtime comment
138-
comment_text = f"# {format_time(original_time)} -> {format_time(optimized_time)} ({perf_gain}%)"
139-
140-
# Add comment to the trailing whitespace
141-
new_trailing_whitespace = cst.TrailingWhitespace(
142-
whitespace=cst.SimpleWhitespace(" "),
143-
comment=cst.Comment(comment_text),
144-
newline=updated_node.trailing_whitespace.newline,
145-
)
146-
147-
return updated_node.with_changes(trailing_whitespace=new_trailing_whitespace)
134+
if original_time != 0 and optimized_time != 0:
135+
perf_gain = format_perf(
136+
performance_gain(original_runtime_ns=original_time, optimized_runtime_ns=optimized_time)
137+
* 100
138+
)
139+
# Create the runtime comment
140+
comment_text = f"# {format_time(original_time)} -> {format_time(optimized_time)} ({perf_gain}%)"
141+
142+
# Add comment to the trailing whitespace
143+
new_trailing_whitespace = cst.TrailingWhitespace(
144+
whitespace=cst.SimpleWhitespace(" "),
145+
comment=cst.Comment(comment_text),
146+
newline=updated_node.trailing_whitespace.newline,
147+
)
148+
149+
return updated_node.with_changes(trailing_whitespace=new_trailing_whitespace)
148150

149151
return updated_node
150152

0 commit comments

Comments
 (0)