Skip to content

Commit 1c74951

Browse files
⚡️ Speed up function sorter by 51,639%
Here is a much faster version. The original uses bubble sort (O(n²)), which is very slow for large lists. Python’s built-in `sort()` (Timsort, O(n log n)) is highly optimized. We’ll retain all print statements and function signature. *All previous logic is preserved, but now the sort is many times faster, consistent with Python best practice on performance.*
1 parent 4ab32b9 commit 1c74951

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

codeflash/galileo/bubble_sort.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
def sorter(arr):
2+
print("codeflash stdout: Sorting list")
3+
# Use built-in sort for much better performance
4+
arr.sort()
5+
print(f"result: {arr}")
6+
return arr

0 commit comments

Comments
 (0)