some profiling utils I want to keep reusing
@profile_call
def test_func(t=2.0):
time.sleep(1.0)
for i in range(10):
test_func(i)
print_prof_data()
times = get_prof_data('test_func'); times
PROF_DATA
clear_prof_data()
@profile_call('wachacha')
def test_func2(t=1.0):
time.sleep(t)
for i in range(10):
test_func2()
print_prof_data()
clear_prof_data()
@profile_call
def test_func3(t=1.0):
time.sleep(1.0)
for i in range(10):
test_func3()
print_prof_data()
for i in range(10):
start_record('timed_sleep')
time.sleep(i)
end_record('timed_sleep')
print_prof_data('timed_sleep')
times2 = get_prof_data('timed_sleep')
As an alternative, the decorator can be invoked this way
sleep = profile_call(time.sleep)
for i in range(5):
sleep(i)
print_prof_data()
We can also specify just the function name to clear from the profile data
clear_prof_data('timed_sleep')
print_prof_data()
sleep = profile_call(time.sleep,'malumam')
for i in range(5):
sleep(1)
print_prof_data()
import pathlib
save_file = 'my_profile_data.pickle'
if pathlib.Path(save_file).is_file(): pathlib.Path(save_file).unlink()
save_prof_data(save_file)
Assert that my_profile_data.pickle
file was created.
assert pathlib.Path(save_file).is_file()
clear_prof_data()
print_prof_data()
PROF_DATA
load_prof_data(save_file)
print_prof_data()
pathlib.Path(save_file).unlink()
import matplotlib.pyplot as plt
plt.plot(times);
plt.plot(times2);