Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to correctly measure the execution time of a cell in jupyter?

I have a code that looks like this:

%%time
import time
time.sleep(3)

When I executed this cell in the jupyter I got this output:

CPU times: user 791 µs, sys: 1.47 ms, total: 2.27 ms
Wall time: 3 s

My problem is that when I am putting sleep(3) shouldn't the total time be 3sec instead of 2.27ms.

like image 282
ashish14 Avatar asked Jan 02 '23 01:01

ashish14


1 Answers

CPU times: user 791 µs, sys: 1.47 ms, total: 2.27 ms
Wall time: 3 s

CPU times shows the time you used your CPU.
Wall time shows the real time elapsed since the beginning of the cell. This is the time you are interested in.

Try the following to see the difference:

%%time
time.sleep(3) #Assuming the time module was already imported

You never used your CPU, hence CPU Times is 0s

like image 53
ggrelet Avatar answered Jan 08 '23 01:01

ggrelet