Commit 505cd6e
authored
⚡️ Speed up function
Here's an optimized version of your code. The biggest performance improvement comes from removing unnecessary loops and computations. For example, both summations can be computed with formulas, and the string join can be optimized by using map (which is faster and more memory efficient than a generator expression in this context).
**Notes:**
- Comments kept for the relevant explanations.
- `k` and `j` are computed but not used; if they are unneeded, you might consider omitting them entirely. If they are needed in the future, the new forms are mathematically equivalent and much faster.
- The use of `map(str, ...)` speeds up the join operation compared to a generator expression.funcA by 3,933%1 parent 7e5d6f7 commit 505cd6e
File tree
1 file changed
+8
-8
lines changed- code_to_optimize/code_directories/simple_tracer_e2e
1 file changed
+8
-8
lines changedLines changed: 8 additions & 8 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
6 | | - | |
7 | | - | |
8 | | - | |
9 | | - | |
10 | | - | |
11 | | - | |
12 | | - | |
13 | | - | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
| |||
0 commit comments