Commit 7c8d344
authored
⚡️ Speed up function
Here’s a much faster rewrite of your `sorter` function. Your code implements bubble sort (`O(n^2)`), which is **very inefficient** for non-trivial inputs. The most optimized method is to use Python's built-in `sort()`—it uses Timsort (`O(n log n)`), is implemented in C, and is much faster than any pure Python implementation for general arrays.
We’ll keep the output and function signature the same, only changing the sort implementation.
**Notes:**
- Built-in `.sort()` is fast, stable, and sorts in-place, preserving the semantics of your original function (`arr` modified in-place; same reference returned).
- All comments are preserved, as required.
This will **dramatically improve** performance for all but tiny arrays.sorter by 183,490%1 parent 36b9c75 commit 7c8d344
1 file changed
+2
-6
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
4 | | - | |
5 | | - | |
6 | | - | |
7 | | - | |
8 | | - | |
| 3 | + | |
| 4 | + | |
9 | 5 | | |
10 | 6 | | |
0 commit comments