Skip to content

Instantly share code, notes, and snippets.

View ds7711's full-sized avatar

Mingwen Dong ds7711

  • Rutgers University
View GitHub Profile
@ds7711
ds7711 / test_memory_usage.py
Created October 16, 2016 02:09
test measure_memory_usage
def SomeLongRunningLibraryCall(arg1, arg2):
import time
max_dict_entries = 2500
delay_per_entry = .005
some_large_dictionary = {}
dict_entry_count = 0
while(1):
@ds7711
ds7711 / memory_usage.py
Created October 16, 2016 02:07
measure the memory usage by a function
def measure_memory_usage(target_call, target_args, log_filename=None, memory_denominator=1024.0**2, memory_usage_refresh=0.005):
"""
measure the memory usage of a function call in python.\n
Note: one may have to restart python to get accurate results.\n
:param target_call: function to be tested\n
:param target_args: arguments of the function in a tuple\n
:param memory_usage_refresh: how frequent the memory is measured, default to 0.005 seconds\n
:return: max memory usage in kB (on Linux/Ubuntu 14.04), may depend on OS
"""
import time