Commit 721dbcb
authored
⚡️ Speed up function
Here’s an optimized version of your code. Improvements.
- `number = min(number, 1000)` is slightly faster and clearer than the original assignment.
- Remove the unnecessary computation of `k` (since it is not used anywhere in the function).
- Preallocate a list of string representations for `" ".join()` rather than using a generator, which is marginally faster when the range is not huge.
- If `number` is often small (<10000), the list allocation is very fast and not a memory/bottleneck concern for these sizes.
If `k` or `j` was needed for side effects, let me know—otherwise, as in your original code, they are unused and should be omitted entirely for maximum performance.
Here’s the rewritten program.
If you do want the values of `k` and `j` to be computed and returned/used, let me know, and I’ll preserve their computation in the most efficient way. This current version exactly matches the function's original behavior (returns the joined string).funcA by 4,438%1 parent 67bd717 commit 721dbcb
File tree
1 file changed
+10
-11
lines changed- code_to_optimize/code_directories/simple_tracer_e2e
1 file changed
+10
-11
lines changedLines changed: 10 additions & 11 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
6 | | - | |
7 | | - | |
8 | | - | |
9 | | - | |
10 | | - | |
11 | | - | |
| 6 | + | |
| 7 | + | |
12 | 8 | | |
13 | | - | |
14 | | - | |
| 9 | + | |
| 10 | + | |
15 | 11 | | |
16 | 12 | | |
17 | 13 | | |
| |||
22 | 18 | | |
23 | 19 | | |
24 | 20 | | |
| 21 | + | |
25 | 22 | | |
26 | 23 | | |
27 | 24 | | |
28 | 25 | | |
29 | 26 | | |
30 | 27 | | |
31 | 28 | | |
32 | | - | |
| 29 | + | |
33 | 30 | | |
34 | 31 | | |
35 | 32 | | |
| |||
44 | 41 | | |
45 | 42 | | |
46 | 43 | | |
| 44 | + | |
47 | 45 | | |
48 | 46 | | |
49 | 47 | | |
| |||
52 | 50 | | |
53 | 51 | | |
54 | 52 | | |
55 | | - | |
| 53 | + | |
56 | 54 | | |
57 | 55 | | |
58 | | - | |
| 56 | + | |
59 | 57 | | |
60 | 58 | | |
61 | 59 | | |
| |||
69 | 67 | | |
70 | 68 | | |
71 | 69 | | |
| 70 | + | |
72 | 71 | | |
73 | 72 | | |
74 | 73 | | |
0 commit comments