CPU time

Measuring CPU time for two functionally identical programs that process identical inputs can indicate which program is faster, but it is a common misunderstanding that CPU time can be used to compare algorithms.

Upon starting a process, the operating system records the time using an internal timer.

When the process is suspended or terminated, the operating system again records the time.

The process "accounting" done by the Unix family of operating systems includes two components of CPU time.

It returns many measurements of a process, often including approximate memory usage and Context switch (scheduling) event counts.

On multi-processor and multi-core machines, a program can use two or more processors simultaneously in what is called parallel processing.

Example: A software application executed on a four-core processor creates four Unix processes.

In reality, parallel processing rarely achieves a linear speedup, where the amount of computation per unit time scales up with the number of processors in use.

Some embarrassingly parallel problems admit such solutions, but for most, additional work is required to divide up the computation when the program starts, and to combine the results from each processor at the end.

CPU Time on Single CPU Multi Tasking System
CPU color time for program P1
top 's display of the CPU time of various processes on a Unix-like ( GNU / Linux ) system