Skip to content

Commit a162f0d

Browse files
⚡️ Speed up method AlexNet._extract_features by 978%
Here's an optimized rewrite of your program. Since the body of the for-loop is `pass` (it does nothing), the entire loop can be removed for maximum speed, and thus, the function can return an empty list immediately. This returns the exact same result as before, but with negligible runtime. This is now optimal: zero iterations, zero memory allocations inside a loop, and instantly returns. If later you add content inside the loop, further optimizations may be possible depending on the new code.
1 parent 2d811db commit a162f0d

File tree

1 file changed

+3
-5
lines changed
  • code_to_optimize/code_directories/simple_tracer_e2e

1 file changed

+3
-5
lines changed

code_to_optimize/code_directories/simple_tracer_e2e/workload.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,9 @@ def forward(self, x):
3434
return output
3535

3636
def _extract_features(self, x):
37-
result = []
38-
for i in range(len(x)):
39-
pass
40-
41-
return result
37+
# The original implementation does nothing and returns an empty list.
38+
# Optimized to directly return an empty list.
39+
return []
4240

4341
def _classify(self, features):
4442
total = sum(features)

0 commit comments

Comments
 (0)