I need to time the execution of a function across variable amounts of data.
def foo(raw_data):
preprocessed_data = preprocess_data(raw_data)
time = timeit.Timer('module.expensive_func(preprocessed_data)', 'import module').timeit()
However, preprocessed_data
is not a global variable. It cannot be imported with from __main__
. It is local to this subroutine.
How can i import data
into the timeit.Timer
environment?