Running the code with the magic command %time in IPython got CPU times
and Wall time
as shown below:
In [1]: %time sum(range(1000000))
CPU times: total: 31.2 ms
Wall time: 26.7 ms
Out[1]: 499999500000
I know Wall time
is wall-clock time or real time and the meaning is the time from when program starts to when program finishes.
But, I don’t know what CPU times
is because the doc doesn’t explain it in detail, just saying:
The CPU and wall clock times are printed`.
I know there are User CPU time and System CPU time as shown below:
-
User CPU time is the amount of the time which program uses CPU on user space. *User space is the memory space for applications.
-
System CPU time is the amount of the time which program uses CPU on kernel space. *Kernel space is the memory space for kernel which is the core of the operating system.
Now, is CPU times
the total of both User CPU time and System CPU time? or either of them? or neither of them?
0
CPU time is the total amount of cycles spent by all CPUs involved executing instructions that belong to your task, expressed using a time unit, whereas wall time (aka “wall-clock time”, “clock time” or “real time”) is the actual amount of time it took to run that task, as if we were measuring it by using a clock that’s hanging on the wall.
(and note that wall time may be less than CPU time if a task ran using more than one core)