====== Timeit ====== By running the line to measure a lot of time (see below), timeit give a median value of consumed time. Simply call it this way (in a Jupyter cell): .. code-block:: python import timeit %timeit to_measure() The output looks like this: .. code-block:: text 1.09 µs ± 32.2 ns per loop (mean ± std. dev. of 7 runs, 1000000 loops each) Timeit typically run the method for a 1'000'000 times so that the result is a median useful value. If the method takes time, timeit will run it less times (down to 10'000 or lower). This is a parameter that you can force if you feel the need ;) There is also the availability to give a defined timer. Command line ============ It is also possible to call it from command line (both of those examples are from the `documentation `_): .. code-block:: console $ python3 -m timeit '"-".join(str(n) for n in range(100))' Or from Python interpreter: .. code-block:: console >>> import timeit >>> timeit.timeit('"-".join(str(n) for n in range(100))', number=10000) :tag:`profiling` :tag:`benchmark` :tag:`snakeviz` :tag:`timeit` :tag:`Python`