Is there a way to see the execution time and execution status in google colab?

Viewed 10613

I am trying to run the notebook in google colab. I am wondering if there is way for me to know if the cell is run and how long it took to run the cell (in milliseconds)

3 Answers

You can do this to get the running time of each cell (similar to the ExecuteTime extension for Jupyter Notebook):

!pip install ipython-autotime
%load_ext autotime

This is how it'll look after running the above code: enter image description here

When you hover over the code block, you can see a sort of play button with a circular progression ring around while it's still running.

To track times, you can add %%timeit at the start of the execution block like

%%timeit
for i in range(1000):
    print(i)
# above is a placeholder for your code

and it will give you the time it took to run the code block in milliseconds. Alternatively you can do %timeit l = [i for i in range(10)] #placeholder for a single line of code to get the execution time for the single line.

You can check the execution time of absolutely anything by calculating the time taken

import time
t1 = time.perf_counter()

### Your code goes here ###

t2 = time.perf_counter()
print('time taken to run:',t2-t1)
Related