Skip to content

Instantly share code, notes, and snippets.

@vaclavcadek
Created January 11, 2022 16:19
Show Gist options
  • Save vaclavcadek/690f17b798145c56c3703bcb4e9a4994 to your computer and use it in GitHub Desktop.
Save vaclavcadek/690f17b798145c56c3703bcb4e9a4994 to your computer and use it in GitHub Desktop.
Simple snippet of how to profile memory in python.
import time
import gc
import psutil
import humanize
gc.collect()
time.sleep(2)
mem_before = psutil.virtual_memory()[3]
dummy_object = [0.0 for _ in range(1_000_000)]
mem_after = psutil.virtual_memory()[3]
print(humanize.naturalsize(mem_after - mem_before))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment