Skip to content

Commit

Permalink
moves class definition into loop, it's slower (#967)
Browse files Browse the repository at this point in the history
  • Loading branch information
charlesfrye authored Nov 12, 2024
1 parent ac142ac commit 46cd7f5
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions 06_gpu_and_ml/torch_profiling.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,13 @@ def underutilize(scale=1):
scale * 100, scale * 100, device="cuda"
)

class Record: # 🐌 1: creating a Python object in the hot loop
def __init__(self, value):
self.value = value

for ii in range(10):
x = x @ x

class Record: # 🐌 1: heavy Python work in the hot loop
def __init__(self, value):
self.value = value

records.append(Record(ii))

x[0][0].cpu() # force a host sync for accurate timing
Expand Down

0 comments on commit 46cd7f5

Please sign in to comment.