Commit 17aa21b
authored
⚡️ Speed up method
Here is an optimized version of your program. The major performance gain comes from using more efficient built-in functions and avoiding unnecessary computation inside the loop.
Key points.
- Instead of creating a list using a list comprehension, use list multiplication, as `total % self.num_classes` is a constant for all elements.
- `sum(features)` is already efficient, but now it is only called once, and the modulo operation is also computed just once.
Optimized code.
This eliminates redundant computation inside the loop, resulting in a much faster classification, especially for large feature vectors.AlexNet._classify by 384%1 parent d03a5f9 commit 17aa21b
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 | |
|---|---|---|---|
| |||
39 | 39 | | |
40 | 40 | | |
41 | 41 | | |
42 | | - | |
43 | | - | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
44 | 45 | | |
45 | 46 | | |
46 | 47 | | |
| |||
0 commit comments