def f():
    pass
timeit.timeit('timeit.timeit("f()", setup="from __main__ import f")', setup
    ='import timeit', number=1000)
timeit.timeit(lambda : timeit.timeit(f), number=100)
Python: is there a way to import a variable using timeit.timeit()?