Created
January 11, 2022 16:19
-
-
Save vaclavcadek/690f17b798145c56c3703bcb4e9a4994 to your computer and use it in GitHub Desktop.
Simple snippet of how to profile memory in python.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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