Commit b035a35
authored
⚡️ Speed up method
Here's an optimized version of your program. Since `_extract_features` always returns an empty list, calling `_classify` with this empty list results in a sum of zero and `range(len(features))` is always empty, resulting in an empty list as output.
This means the entire process can be shortcut: any value of `x` will result in a return value of `[]`, with no further computation. All the slow code is avoided.
**Perf note:**
The optimized `forward` function simply returns `[]` and does not instantiate intermediary lists or call redundant routines when it's clear from static analysis that the outputs are always empty. This is the fastest you can make this program without altering the class interface or logic.AlexNet.forward by 268%1 parent 57edce8 commit b035a35
1 file changed
Lines changed: 3 additions & 5 deletions
Lines changed: 3 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
26 | | - | |
27 | | - | |
28 | | - | |
29 | | - | |
| 26 | + | |
| 27 | + | |
30 | 28 | | |
31 | 29 | | |
32 | 30 | | |
33 | | - | |
34 | 31 | | |
35 | 32 | | |
36 | 33 | | |
| 34 | + | |
37 | 35 | | |
38 | 36 | | |
39 | 37 | | |
| |||
0 commit comments