Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@timcharper
Created May 13, 2020 18:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save timcharper/8184952a90444682eecc9149582d6f72 to your computer and use it in GitHub Desktop.
Save timcharper/8184952a90444682eecc9149582d6f72 to your computer and use it in GitHub Desktop.
Allocate n mb per second
#!/usr/bin/env python3
from time import sleep
from sys import exit, argv, getsizeof
# this simple python script allocates memory, waits for a while, and then exits successfully
mem = 0
allocs = []
try:
mem = int(argv[1])
except ValueError:
print("Usage: mem.py <mb-to-allocate-per-cycle>")
exit()
bytes = mem * 1024 * 1024
print("Allocating {} bytes".format(bytes), flush=True)
while True:
sleep(1)
allocs.append(bytearray(bytes))
total_size = 0
for e in allocs:
total_size = total_size + getsizeof(e)
print("Allocated size: {}...".format(total_size), flush=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment