Skip to content

Instantly share code, notes, and snippets.

@spider-man-tm
Created July 15, 2021 11:19
Show Gist options
  • Save spider-man-tm/f616e4b31e2c503152d9aca569dd78be to your computer and use it in GitHub Desktop.
Save spider-man-tm/f616e4b31e2c503152d9aca569dd78be to your computer and use it in GitHub Desktop.
各変数のメモリ使用量を表示する
print("{}{: >25}{}{: >10}{}".format('|', 'Variable Name', '|', 'Memory', '|'))
print(" ------------------------------------ ")
for var_name in dir():
if not var_name.startswith("_") and sys.getsizeof(eval(var_name)) > 10000:
print("{}{: >25}{}{: >10}{}{: >5}{}".format(
'|', var_name, '|', sys.getsizeof(eval(var_name)), '|', sys.getrefcount(var_name), '|'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment