python - Importing a local variable in a function into timeit -
i need time execution of 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
not global variable. cannot imported from __main__
. local subroutine.
how can import data
timeit.timer
environment?
pass callable time, rather string. (unfortunately, introduces function call overhead, it's viable when thing time swamps overhead.)
time = timeit.timeit(lambda: module.expensive_func(data))
Comments
Post a Comment