timeit
Timeit is a Python standard library module for measuring the execution time of small code snippets. It focuses on accuracy and minimal overhead by repeatedly executing the target code and by isolating setup work, using a high-resolution timer. Time measurements produced are intended to help compare implementations or micro-optimize code rather than to benchmark long-running tasks.
The module provides two primary interfaces: a functional interface timeit.timeit and a Timer class. Both accept
Usage example: timeit.timeit("sum(range(10))", setup="from itertools import accumulate", number=1000). Or using a Timer: t = timeit.Timer("sum(range(10))"); t.timeit(1000). For
Notes: For more stable results, disable garbage collection during timing and perform multiple repeats with a