timeit.Timer()
timeit.Timer() is a Python function in the Timeit Module category. Creates a Timer object for repeated timing of code. The syntax is timeit.Timer(stmt="pass", setup="pass", timer=default_timer, globals=None). Returns: Timer object. A typical example: t = timeit.Timer("x = sum(range(100))")
print(t.timeit(1000)). A close sibling is timeit.timeit(), which times the execution of a small Python code snippet. A close sibling is timeit.repeat(), which like timeit() but runs multiple times and returns a list of results. A close sibling is timeit.default_timer(), which default timer for timeit (uses time.perf_counter). More about this category: Code timing — timeit, repeat, default_timer. Related Timeit Module entries: timeit.timeit(), timeit.repeat(), timeit.default_timer(). This page is part of the free Python Reference documentation covering 978+ functions, methods, and modules with examples and parameter details. You can try timeit.Timer() immediately in the Python playground, look up unfamiliar terms in the glossary, or return to the Python Reference homepage.