CPU time
Encyclopedia
CPU time is the amount of time
for which a central processing unit
(CPU) was used for processing instructions of a computer program
, as opposed to, for example, waiting for input/output
(I/O) operations. The CPU time is often measured in clock ticks or as a percentage of the CPU's capacity. It is used as a point of comparison for CPU workload of a program.
In contrast, elapsed real time
(or simply real time, or wall clock time) is the time taken from the start of a computer program until the end as measured by an ordinary clock. Elapsed real time includes I/O time and all other types of waits incurred by the program.
command top provides CPU time, priority, elapsed real time
, and other information for all processes and updates it in real time.
command time
prints CPU time and elapsed real time for a Unix process.
This process took a total of 0.337 seconds of CPU time, out of which 0.327 seconds was spent in user space, and the final 0.010 seconds in kernel mode on behalf of the process. Elapsed real time
was 1.15 seconds.
The following is the source code of the application nextPrimeNumber which was used in the above example.
POSIX functions
POSIX functions
, the CPU time consumed by all individual threads
of the process are added.
Total CPU time
On multi-processor
machines, a computer program can use two or more CPUs for processing using parallel processing
scheduling. In such situations, the notion of total CPU time is used, which is the sum of CPU time consumed by all of the CPUs utilized by the computer program.
CPU time and elapsed real time
Elapsed real time is always the same or more than CPU time for computer program which use only one CPU for processing. If no wait is involved for I/O or other resources, elapsed real time and CPU time are very similar.
, total CPU time for that program would be more than its elapsed real time. (Total CPU time)/(Number of CPUs) is used to calculate elapsed real time if work load is evenly distributed on each CPU and no wait is involved for I/O or other such external resources.
Example: A software application executed on a Hexa-core processor creates three Unix processes for fulfilling the user requirement. Each of these three processes creates two threads, enumerating a total of 6 working threads. Computation is distributed evenly on the 6 independent threads. If no wait for resources is involved, total CPU time is expected to be six times the elapsed real time.
See also
Time
Time is a part of the measuring system used to sequence events, to compare the durations of events and the intervals between them, and to quantify rates of change such as the motions of objects....
for which a central processing unit
Central processing unit
The central processing unit is the portion of a computer system that carries out the instructions of a computer program, to perform the basic arithmetical, logical, and input/output operations of the system. The CPU plays a role somewhat analogous to the brain in the computer. The term has been in...
(CPU) was used for processing instructions of a computer program
Computer program
A computer program is a sequence of instructions written to perform a specified task with a computer. A computer requires programs to function, typically executing the program's instructions in a central processor. The program has an executable form that the computer can use directly to execute...
, as opposed to, for example, waiting for input/output
Input/output
In computing, input/output, or I/O, refers to the communication between an information processing system , and the outside world, possibly a human, or another information processing system. Inputs are the signals or data received by the system, and outputs are the signals or data sent from it...
(I/O) operations. The CPU time is often measured in clock ticks or as a percentage of the CPU's capacity. It is used as a point of comparison for CPU workload of a program.
In contrast, elapsed real time
Elapsed real time
Elapsed real time is the time taken from start of computer program to the end. Elapsed real time includes I/O time and all other types of wait.Elapsed Real time is the time measured by an ordinary clock....
(or simply real time, or wall clock time) is the time taken from the start of a computer program until the end as measured by an ordinary clock. Elapsed real time includes I/O time and all other types of waits incurred by the program.
Unix commands for CPU time
Unix command top
The UnixUnix
Unix is a multitasking, multi-user computer operating system originally developed in 1969 by a group of AT&T employees at Bell Labs, including Ken Thompson, Dennis Ritchie, Brian Kernighan, Douglas McIlroy, and Joe Ossanna...
command top provides CPU time, priority, elapsed real time
Elapsed real time
Elapsed real time is the time taken from start of computer program to the end. Elapsed real time includes I/O time and all other types of wait.Elapsed Real time is the time measured by an ordinary clock....
, and other information for all processes and updates it in real time.
Unix command time
The UnixUnix
Unix is a multitasking, multi-user computer operating system originally developed in 1969 by a group of AT&T employees at Bell Labs, including Ken Thompson, Dennis Ritchie, Brian Kernighan, Douglas McIlroy, and Joe Ossanna...
command time
Time (Unix)
time is a command in the Unix operating systems. It is used to determine the duration of execution of a particular command.-Usage:To use the command, simply precede any command by the word time, such as:time ls...
prints CPU time and elapsed real time for a Unix process.
% time nextPrimeNumber 30000007
Prime number greater than 30000007 is 30000023
0.327u 0.010s 0:01.15 28.6% 0+0k 0+0io 0pf+0w
This process took a total of 0.337 seconds of CPU time, out of which 0.327 seconds was spent in user space, and the final 0.010 seconds in kernel mode on behalf of the process. Elapsed real time
Elapsed real time
Elapsed real time is the time taken from start of computer program to the end. Elapsed real time includes I/O time and all other types of wait.Elapsed Real time is the time measured by an ordinary clock....
was 1.15 seconds.
The following is the source code of the application nextPrimeNumber which was used in the above example.
POSIX functions clock
and getrusage
POSIX functionsC POSIX library
The C POSIX library is a specification of a C standard library for POSIX systems. It was developed at the same time as the ANSI C standard. Some effort was made to make POSIX compatible with standard C; POSIX includes additional functions to those introduced in standard C.- C POSIX library header...
clock
and getrusage
can be used to get CPU time consumed by any process in a POSIX environment. If the process is multithreadedThread (computer science)
In computer science, a thread of execution is the smallest unit of processing that can be scheduled by an operating system. The implementation of threads and processes differs from one operating system to another, but in most cases, a thread is contained inside a process...
, the CPU time consumed by all individual threads
Thread (computer science)
In computer science, a thread of execution is the smallest unit of processing that can be scheduled by an operating system. The implementation of threads and processes differs from one operating system to another, but in most cases, a thread is contained inside a process...
of the process are added.
Total CPU time
On multi-processor
Multiprocessing
Multiprocessing is the use of two or more central processing units within a single computer system. The term also refers to the ability of a system to support more than one processor and/or the ability to allocate tasks between them...
machines, a computer program can use two or more CPUs for processing using parallel processing
Parallel computing
Parallel computing is a form of computation in which many calculations are carried out simultaneously, operating on the principle that large problems can often be divided into smaller ones, which are then solved concurrently . There are several different forms of parallel computing: bit-level,...
scheduling. In such situations, the notion of total CPU time is used, which is the sum of CPU time consumed by all of the CPUs utilized by the computer program.
CPU time and elapsed real time
Elapsed real time is always the same or more than CPU time for computer program which use only one CPU for processing. If no wait is involved for I/O or other resources, elapsed real time and CPU time are very similar.
CPU time and elapsed real time for parallel processing technology
If a program uses parallel processingParallel processing
Parallel processing is the ability to carry out multiple operations or tasks simultaneously. The term is used in the contexts of both human cognition, particularly in the ability of the brain to simultaneously process incoming stimuli, and in parallel computing by machines.-Parallel processing by...
, total CPU time for that program would be more than its elapsed real time. (Total CPU time)/(Number of CPUs) is used to calculate elapsed real time if work load is evenly distributed on each CPU and no wait is involved for I/O or other such external resources.
Example: A software application executed on a Hexa-core processor creates three Unix processes for fulfilling the user requirement. Each of these three processes creates two threads, enumerating a total of 6 working threads. Computation is distributed evenly on the 6 independent threads. If no wait for resources is involved, total CPU time is expected to be six times the elapsed real time.
See also
- Elapsed real timeElapsed real timeElapsed real time is the time taken from start of computer program to the end. Elapsed real time includes I/O time and all other types of wait.Elapsed Real time is the time measured by an ordinary clock....
- CPU
- Process (computing)Process (computing)In computing, a process is an instance of a computer program that is being executed. It contains the program code and its current activity. Depending on the operating system , a process may be made up of multiple threads of execution that execute instructions concurrently.A computer program is a...
- System time
- topTop (Unix)top is a program found in many Unix-like operating systems. It produces an ordered list of running processes selected by user-specified criteria, and updates it periodically. Default ordering by CPU usage, and only the top CPU consumers shown top shows how much processing power and memory are...
- mpstatMpstatmpstat is a computer command-line software used in unix-type operating systems to report processor related statistics. It is used in computer monitoring in order to diagnose problems or for build statistics about a computer CPU usage....
- Load (computing)Load (computing)In UNIX computing, the system load is a measure of the amount of work that a computer system performs. The load average represents the average system load over a period of time...