from timeit import timeit

function = "def f(x): pass\n"
loop = "for x in range(1000):\n"
call = "    f(x)"

# execute each test 10,000 times
params = { 'number' : 10000, 'globals': globals() }

# execution times are in seconds

# create the function before the loop
print(timeit(f'{function}{loop}{call}', **params))
# create the function inside the loop
print(timeit(f'{loop}    {function}{call}', **params))
