Measuring execution time

BB2Lon report abuse

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?


Tinkerberg report abuse

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:

# code for execution

In the output, you will see the time used to complete the cell execution.

Add Answer

Need support?

Just drop us an email to ... Show more