News

python -m timeit "for n in range(100):pass" On the whole, though, it’s easier to use the technique shown above, since you don’t need to awkwardly shoehorn your code into a text string.
The 'timeit' module provides a simple way to time small bits of Python code. It has both a command-line interface and a callable one. Typically, you'd import 'timeit' and use the 'timeit.timeit ...
Just save the time before and after the execution of code and subtract them! But this method is not precise as there might be a background process momentarily running which disrupts the code execution ...
$ docker run --privileged -it -v $(pwd):/timeit python:3.6.7-slim python3 /timeit/timeit_chaos.py Python version: 3.6.7 (default, Nov 16 2018, 06:39:52) [GCC 6.3.0 20170516] Running 3 times, 10X chaos ...