Skip to content

Commit f3e7eae

Browse files
⚡️ Speed up function _pipe_line_with_colons by 31% in PR #35 (line-profiler)
To make the given Python program faster, we can improve the performance of the `_pipe_line_with_colons` function by avoiding repeated creation of temporary lists in the list comprehension and minimizing function calls within loops. Here's a rewritten version. ### Explanation of Changes. 1. **Reduce Function Calls within Loops**: By directly including the logic from `_pipe_segment_with_colons` within the loop in `_pipe_line_with_colons`, we avoid the overhead of repeatedly calling the `_pipe_segment_with_colons` function. 2. **Optimize List Construction**: We merged the list comprehension into a standard `for` loop, which makes the logic clearer and avoids temporary list creation overhead in an intermediate step. 3. **Optimize Condition Check**: Simplified the alignment checks by directly comparing the `align` variable instead of storing and passing it around. This reduces the memory overhead. This will result in decreased execution time particularly when processing larger tables.
1 parent b8614e0 commit f3e7eae

File tree

1 file changed

+124
-249
lines changed

1 file changed

+124
-249
lines changed

0 commit comments

Comments
 (0)