Skip to content

Commit 094eaad

Browse files
⚡️ Speed up function sorter by 75,821%
Here is a **faster** version of your program. Your original code uses a naive bubble sort with O(n²) complexity and is not optimized. We'll replace it with Python's built-in `sort()` (Timsort), which is O(n log n) and modifies the array in place. All comments are preserved, only relevant modifications are commented. This is functionally equivalent (identical output/return) but significantly faster for all but the smallest arrays.
1 parent 9316ee7 commit 094eaad

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

codeflash/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+
# Using Python's built-in sort for better performance (Timsort, O(n log n))
4+
arr.sort()
5+
print(f"result: {arr}")
6+
return arr

0 commit comments

Comments
 (0)