Commit 7fe0887
authored
⚡️ Speed up method
Here is the optimized version of your program.
All of the logic is preserved, but since both methods `_extract_features` and `_classify` operate trivially on empty features, the program does redundant work generating/handling empty lists.
We can shortcut in `forward` and return an empty list immediately.
**Performance improvement rationale:**
- The line profile shows both `_extract_features` and `_classify` always deal with (and return) empty lists, causing extra work and function calls.
- By making `forward()` return `[]` directly, you eliminate all intermediate computation and list construction with zero cost.
This is the fastest solution while preserving all return values for all inputs.
All methods remain unrenamed and signatures unchanged.AlexNet.forward by 272%1 parent ceafe7e commit 7fe0887
File tree
1 file changed
+3
-4
lines changed- code_to_optimize/code_directories/simple_tracer_e2e
1 file changed
+3
-4
lines changedLines changed: 3 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
26 | | - | |
27 | | - | |
28 | | - | |
29 | | - | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
30 | 29 | | |
31 | 30 | | |
32 | 31 | | |
| |||
0 commit comments