Last active
September 26, 2020 02:19
-
-
Save rtobar/b1a83a4712f810e6aa227cff988609fc to your computer and use it in GitHub Desktop.
This file contains 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 gc | |
import os | |
import resource | |
import sys | |
import time | |
def memusage(): | |
"""memory usage in MB. getrusage defaults to KB on Linux.""" | |
return resource.getrusage(resource.RUSAGE_SELF).ru_maxrss / 1e3 | |
def run(): | |
print("Python %s" % sys.version) | |
print("Memory usage at start: %.2f MB" % memusage()) | |
t_start = time.time() | |
for i in range(4000000): | |
pass | |
print("spent time: {:.2f}".format(time.time() - t_start)) | |
print("Memory usage after loop: %.2f MB" % memusage()) | |
gc.collect() | |
print("Memory usage after GC: %.2f MB" % memusage()) | |
if __name__ == "__main__": | |
run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment