Skip to content

Instantly share code, notes, and snippets.

@ollien
Created July 29, 2024 17:14
Show Gist options
  • Save ollien/d71bc5b209a1cd69426d2905e01d534f to your computer and use it in GitHub Desktop.
Save ollien/d71bc5b209a1cd69426d2905e01d534f to your computer and use it in GitHub Desktop.
Tracemalloc Test, Narrowed
[~/Documents/code] nick.krichevsky@M3M-NKrichevsky$ python3 tracemalloc_test.py
Total: 64, Peak: 30040
Total: 64, Peak: 363040
Total: 64, Peak: 30040
import tracemalloc
def allocate(n):
list(range(n))
def print_snap(snap: tracemalloc.Snapshot):
for (i, frame) in enumerate(snap.statistics('traceback')):
print(f' Frame {i}: {frame}')
tracemalloc.start()
allocate(1000)
total, peak = tracemalloc.get_traced_memory()
tracemalloc.stop()
print(f"Total: {total}, Peak: {peak}")
tracemalloc.start()
allocate(10000)
total, peak = tracemalloc.get_traced_memory()
tracemalloc.stop()
print(f"Total: {total}, Peak: {peak}")
tracemalloc.start()
allocate(1000)
total, peak = tracemalloc.get_traced_memory()
tracemalloc.stop()
print(f"Total: {total}, Peak: {peak}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment