timeit.repeat()
timeit.repeat() is a Python function in the Timeit Module category. Like timeit() but runs multiple times and returns a list of results. The syntax is timeit.repeat(stmt="pass", setup="pass", timer=default_timer, repeat=5, number=1000000, globals=None). Returns: List of float times. A typical example: times = timeit.repeat("x = sum([1,2,3])", repeat=3, number=10000)
min(times) # Best time. A close sibling is timeit.timeit(), which times the execution of a small Python code snippet. A close sibling is timeit.default_timer(), which default timer for timeit (uses time.perf_counter). A close sibling is timeit.Timer(), which creates a Timer object for repeated timing of code. More about this category: Code timing — timeit, repeat, default_timer. Related Timeit Module entries: timeit.timeit(), timeit.default_timer(), timeit.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.repeat() immediately in the Python playground, look up unfamiliar terms in the glossary, or return to the Python Reference homepage.