@@ -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