Measuring execution time
I am writing a Python script in Jupyter Notebook and it is important to measure the execution time of some pieces of code. What is the most convenient way to do this?
I am writing a Python script in Jupyter Notebook and it is important to measure the execution time of some pieces of code. What is the most convenient way to do this?
Hi @BB2Lon
There are several methods. For example, you can use the time module to make to points (start and finish) and then compute the difference between the finish point and the start point. E.g.
import time
start = time.time()
# code for execution
finish = time.time()
duration = finish - start
But since you use Jupyter Notebook, you can just use the %%time magic. It will measure the runtime of the particular cell:
%%time
# code for execution
In the output, you will see the time used to complete the cell execution.
Just drop us an email to ... Show more