Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does these parameters mean in jupyter notebook when I input "%%time"?

  1. I create a new cell in my jupyter notebook.
  2. I type %%time in the first line of my new cell.
  3. I type some codes in the second line.
  4. I run this cell and get some information as follows

    CPU times: user 2min 8s, sys: 14.5 s, total: 2min 22s

    Wall time: 1min 29s

My question is what does these parameters mean? CPU times, user, sys, total(I think that it means user+total), Wall time

like image 737
SSQ Avatar asked Jan 11 '18 08:01

SSQ


People also ask

What is %% time in Jupyter Notebook?

%%timeit in Jupyter Notebook The “%%timeit” command is used to measure the execution time of the entire cell code and can contain several code lines that may be written in the next line. The “%%timeit” is easiest to use because you need to enter “%%timeit” only at the start of the cell.

What does %% do in Jupyter Notebook?

Both ! and % allow you to run shell commands from a Jupyter notebook. % is provided by the IPython kernel and allows you to run "magic commands", many of which include well-known shell commands. ! , provided by Jupyter, allows shell commands to be run within cells.

How does Jupyter Notebook Show execution time?

Run the %timeit command on a command-line or jupyter notebook to get the execution time of a single line of code.

How do you view parameters in a Jupyter Notebook?

Documentation: Jupyter Notebook can show that documentation of the function you are calling. Press Shift+Tab to view the documentation. This is very helpful as you don't need to open the documentation website every single time.


1 Answers

If we run the code below in a cell:

%%time

from time import sleep

for i in range(3):
    print(i, end=' ')
    sleep(0.1)

The output is:

0 1 2 
CPU times: user 5.69 ms, sys: 118 µs, total: 5.81 ms
Wall time: 304 ms

The wall time means that a clock hanging on a wall outside of the computer would measure 304 ms from the time the code was submitted to the CPU to the time when the process completed.

User time and sys time both refer to time taken by the CPU to actually work on the code. The CPU time dedicated to our code is only a fraction of the wall time as the CPU swaps its attention from our code to other processes that are running on the system.

User time is the amount of CPU time taken outside of the kernel. Sys time is the amount of time taken inside of the kernel. The total CPU time is user time + sys time. The differences between user and sys time is well explained in the post:

What do 'real', 'user' and 'sys' mean in the output of time(1)?

like image 170
Oppy Avatar answered Oct 11 '22 22:10

Oppy