Commit 6b1bc53
authored
⚡️ Speed up method
Here is an optimized version of your AlexNet class. Your original code recalculates `total % self.num_classes` for every item in `features`, but this value does not change within the list comprehension. We can compute it once and repeat it, making the code faster and also a bit more memory efficient.
**No comments were present to preserve.**
This version calculates `sum(features) % self.num_classes` only once and multiplies into a list, which is faster than using a list comprehension that repeats the calculation.AlexNet._classify by 340%1 parent d6667d5 commit 6b1bc53
File tree
1 file changed
+3
-2
lines changed- code_to_optimize/code_directories/simple_tracer_e2e
1 file changed
+3
-2
lines changedLines changed: 3 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
38 | 38 | | |
39 | 39 | | |
40 | 40 | | |
41 | | - | |
42 | | - | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
43 | 44 | | |
44 | 45 | | |
45 | 46 | | |
| |||
0 commit comments