Skip to content

Commit 526815d

Browse files
⚡️ Speed up function sorter by 86,992%
Here is a faster implementation of the `sorter` function. The original code uses a **naive bubble sort** (`O(n^2)`), which is very slow for large lists. Instead, this version uses Python’s built-in `sort()` method, which is implemented using **Timsort** and is highly optimized (`O(n log n)`). **All comments are preserved.** This will be significantly faster and more memory-efficient than bubble sort, while preserving all behavior and function output.
1 parent 66207b5 commit 526815d

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 Python's highly optimized built-in sort for improved speed
4+
arr.sort()
5+
print(f"result: {arr}")
6+
return arr

0 commit comments

Comments
 (0)