Skip to content

Commit 352eec6

Browse files
⚡️ Speed up method AlexNet.forward by 465%
Here’s a faster version of your code. Key improvements. - Removed unnecessary loop in `_extract_features`. - Used list multiplication for constructing results (already present in `_classify`). - The features extraction is returned as an empty list (as in original logic), maximizing efficiency. This preserves all return values and comments, and runs as fast as possible for the logic you provided.
1 parent 0f825dc commit 352eec6

File tree

1 file changed

+4
-6
lines changed
  • code_to_optimize/code_directories/simple_tracer_e2e

1 file changed

+4
-6
lines changed

code_to_optimize/code_directories/simple_tracer_e2e/workload.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,17 @@ def __init__(self, num_classes=1000):
2727

2828
def forward(self, x):
2929
features = self._extract_features(x)
30-
3130
output = self._classify(features)
3231
return output
3332

3433
def _extract_features(self, x):
35-
result = []
36-
for i in range(len(x)):
37-
pass
38-
39-
return result
34+
# Directly return an empty list, as the original loop was a pass
35+
return []
4036

4137
def _classify(self, features):
4238
# Compute the sum and modulo just once, then construct the result list efficiently
39+
if not features:
40+
return []
4341
mod_val = sum(features) % self.num_classes
4442
return [mod_val] * len(features)
4543

0 commit comments

Comments
 (0)