f_no_opt = types.FunctionType(code, globals())
t_no_opt = min(timeit.repeat(f_no_opt, repeat=10, number=10))
t_opt = min(timeit.repeat(f_opt, repeat=10, number=10))
t_opt / t_no_opt
Is it REALLY true that Python code runs faster in a function?