Skip to content

Instantly share code, notes, and snippets.

@ephes
Created September 23, 2020 05:11
Show Gist options
  • Save ephes/bc7e9adce9d16cec93baa279ca6a10bb to your computer and use it in GitHub Desktop.
Save ephes/bc7e9adce9d16cec93baa279ca6a10bb to your computer and use it in GitHub Desktop.
import os
import time
import math
import psutil
def convert_size(size_bytes):
if size_bytes == 0:
return "0B"
size_name = ("B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB")
i = int(math.floor(math.log(size_bytes, 1024)))
p = math.pow(1024, i)
s = round(size_bytes / p, 2)
return s, size_name[i]
# allocate a list with 10 million entries
big_number = 1000 * 1000 * 10
# big_list = list(range(big_number))
big_list = [10 for _ in range(big_number)]
print(len(big_list))
# time.sleep(100)
process = psutil.Process(os.getpid())
memory_in_bytes = process.memory_info().rss
print(convert_size(memory_in_bytes))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment