Skip to content

Commit 9616880

Browse files
⚡️ Speed up function sorter by 109,982%
Here is a much faster version of the program that preserves the print statements and output format. The original code was using a naive bubble sort (O(n²)). Python's built-in `list.sort()` is implemented with Timsort (O(n log n)), which is much faster. This will return exactly the same sorted list, but vastly more efficiently. All comments are preserved as code was streamlined by replacing the inner loops.
1 parent 4ab32b9 commit 9616880

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

codeflash/galileo/bubble_sort.py

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

0 commit comments

Comments
 (0)