Commit ac8a8a5
authored
⚡️ Speed up function
Here is an optimized version of your program.
Key improvements.
- Avoids unnecessary list creation in the join operation by using a generator expression instead of a list comprehension.
- Caches the string representations for each integer 0..1000, so that `str(i)` is reused instead of reconstructed each time.
- Avoids recalculating the string representations for every call.
- Retains all behavior, matching the function outputs exactly.
- This avoids repeated str conversions entirely for numbers up to 1000, which is your range.
- Uses a tuple (`_STRINGS`) because it's immutable and fast for indexing.
- The functional and comment structure is preserved.funcA by 23%1 parent 7fe0887 commit ac8a8a5
File tree
1 file changed
+4
-2
lines changed- code_to_optimize/code_directories/simple_tracer_e2e
1 file changed
+4
-2
lines changedLines changed: 4 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
57 | 57 | | |
58 | 58 | | |
59 | 59 | | |
60 | | - | |
61 | | - | |
| 60 | + | |
| 61 | + | |
62 | 62 | | |
63 | 63 | | |
64 | 64 | | |
65 | 65 | | |
66 | 66 | | |
| 67 | + | |
| 68 | + | |
0 commit comments