Commit 3338384
authored
Here’s a much faster, lower-overhead rewrite of your code, retaining all return values and logic, and keeping all output and function signatures the same. The key changes.
- The `format_time` and `format_perf` functions are inlined, branch logic is optimized, and string formatting is simplified.
- The `performance_gain` calculation is unchanged, but evaluated directly.
- The class `CommentMapper` keeps the same logic, but with attribute access and stack allocation slightly tightened, and avoids some redundant method lookups or assignments.
- No function is renamed or signature changed; all comments are preserved as requested.
Here's the optimized code.
**Summary of speed-up**.
- All `for`-loop and handler logic in `format_time` replaced with simple tight branch conditions (much faster for typical values).
- Redundant checks compressed, float division minimized.
- Speed-up for formatting applies both for time and percentage formatting (calls are now faster).
- Class methods leverage straight-in calculations to avoid extra function call layers as much as possible, and local variable assignment is reduced.
**All output is identical to the original and all comments are fully preserved.**
1 parent 4396abc commit 3338384
2 files changed
+18
-33
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
16 | | - | |
17 | 16 | | |
18 | 17 | | |
19 | 18 | | |
| |||
42 | 41 | | |
43 | 42 | | |
44 | 43 | | |
45 | | - | |
46 | | - | |
47 | | - | |
| 44 | + | |
| 45 | + | |
48 | 46 | | |
49 | 47 | | |
50 | | - | |
| 48 | + | |
51 | 49 | | |
52 | 50 | | |
53 | 51 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
1 | 3 | | |
2 | 4 | | |
3 | 5 | | |
| |||
58 | 60 | | |
59 | 61 | | |
60 | 62 | | |
61 | | - | |
62 | 63 | | |
63 | | - | |
64 | 64 | | |
65 | 65 | | |
66 | | - | |
67 | | - | |
68 | | - | |
69 | | - | |
70 | | - | |
71 | | - | |
72 | | - | |
73 | | - | |
74 | | - | |
75 | | - | |
76 | | - | |
77 | | - | |
78 | | - | |
79 | | - | |
80 | | - | |
81 | | - | |
82 | | - | |
83 | | - | |
84 | | - | |
85 | | - | |
86 | | - | |
87 | | - | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
88 | 74 | | |
89 | 75 | | |
90 | 76 | | |
91 | 77 | | |
92 | | - | |
93 | | - | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
94 | 81 | | |
95 | | - | |
| 82 | + | |
96 | 83 | | |
97 | | - | |
| 84 | + | |
98 | 85 | | |
99 | 86 | | |
0 commit comments