Commit 867e138
authored
⚡️ Speed up method
Here is an optimized version of your program. The main area to optimize is the `_classify` method: using `sum()` is already efficient, but `[val for _ in features]` can be replaced with list multiplication, which is faster in Python. We also avoid recalculating `total % self.num_classes` for every element.
This runs faster, especially for large lists of `features`, because the modulo is computed just once and the resultant list is constructed in a single step.AlexNet._classify by 371%1 parent 030e1e5 commit 867e138
File tree
1 file changed
+2
-2
lines changed- code_to_optimize/code_directories/simple_tracer_e2e
1 file changed
+2
-2
lines changedLines changed: 2 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
36 | 36 | | |
37 | 37 | | |
38 | 38 | | |
39 | | - | |
40 | | - | |
| 39 | + | |
| 40 | + | |
41 | 41 | | |
42 | 42 | | |
43 | 43 | | |
| |||
0 commit comments