Example from documentation
def test():
"""Stupid test function"""
L = []
for i in range(100):
L.append(i)
if __name__ == '__main__':
import timeit
print(timeit.timeit("test()", setup="from __main__ import test"))
but how to call a function with parameters, for example, a function like this:
def test(some_object):
"""Stupid test function"""
L = []
for i in range(100):
L.append(some_object)
print(timeit.timeit("test(5)", setup="from __main__ import test"))
. If you want to use an argument that's an object you define outside the timeit code, you have to import it like anything else. The timeit string is just normal Python code, everything works as usual. – Twinkle