24
  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

SSQ
  • 355
  • 1
  • 2
  • 7

1 Answers1

31

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)?

Oppy
  • 2,662
  • 16
  • 22
  • Thanks for your answer and link. I can understand the `Wall time`. But I need more time to understand the `sys`, `user` and `kernel`. – SSQ Jan 15 '18 at 03:55
  • I only understand the basics. The link provides an in depth coverage of the topic. If my post did provide enough to answer your question, please accept it. – Oppy Jan 19 '18 at 11:19
  • 2
    I actually have a case where the wall time is less than the user and total time, which is confusing. Can you explain that? – NeStack May 04 '20 at 13:00
  • 1
    Perhaps the process has forked and the children are running in parallel on a multi-core system. All of the childrens' run times will be added together even though they are running in parallel, giving a greater value than the wall time. – Oppy May 05 '20 at 17:08
  • 1
    this is my output: CPU times: user 32min 24s, sys: 26.6 s, total: 32min 50s ; Wall time: 16min 30s. so this cell takes 16min real world time to run, but CPU takes 32min to work on the code? why is cpu time longer than real time? – Sam-gege Oct 10 '21 at 05:45
  • I think my earlier comment answers why cpu time can be greater than wall time. There is more information on this here https://stackoverflow.com/a/17843951/7222588. – Oppy Oct 13 '21 at 09:05