Share on Facebook Share on Twitter Email
Answers.com

CPU time

 

The amount of time it takes for the CPU to execute a set of instructions and generally excludes the waiting time for input and output.

Download Computer Desktop Encyclopedia to your iPhone/iTouch

Search unanswered questions...
Enter a question here...
Search: All sources Community Q&A Reference topics
Wikipedia: CPU time
Top
Display of the CPU time (using top) of various processes on a Unix-like (GNU/Linux) system (the “TIME+” column).

CPU time or CPU usage is the amount of time for which central processing unit (CPU) was used for processing instructions of a computer program , as opposed to, for example, waiting for the input/output operations. The CPU time is often measured in clock ticks or in percentage of the capacity. It is used as a point of comparison for CPU usage of a program.

On the other hand, Elapsed real time ( or simply 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.

Contents

Unix command time

Unix command time prints cpu time and elapsed real time for an 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 total of 0.337 seconds of CPU time. Out of which 0.327 seconds was spent in user space and rest 0.010 seconds in kernel mode on behalf of the process. Elapsed real time was 1.15 seconds.

Source code of application nextPrimeNumber used in above example.

#include <stdio.h>
#include <stdlib.h>
 
int isPrimeNumber(int n) {
  int i;
  for(i=2; i<=(n/2); i++)
    if(n%i==0) return 0;
  return 1;
}
 
int main(int argc , char *argv[]) {
  int n=atoi(argv[1]);
  while(!isPrimeNumber(++n)) ;
  printf("Prime number greater than %d is %d\n", atoi(argv[1]), n);
  return 0;
}

Posix function clock() and getrusage()

Posix functions clock() or getrusage() can be used to get cpu time for the process.

Unix command time and Posix functions clock() and getrusage() provide CPU time consumed by the Unix process . If process is multi-threaded, cpu time consumed by all individual threads of process are added.

Total CPU time

A computer program can use two or more CPUs at the same time for processing using parallel processing technology. In such situation notion of Total CPU time is used. Total CPU time is the addition of CPU time consumed by all CPUs used by the computer program.

CPU time and elapsed real time

Elapsed real time is always 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

Total CPU time for computer program which uses parallel processing technology could be more than Elapsed real time. Elapsed real time is (Total CPU time)/(Number of CPUs) used if wait is involved for I/O or other resources and work load is evenly distributed on each CPU.

Example: A software application running in 6-CPU UNIX machine creates three UNIX processes for fulfilling the user requirement. Each of these three processes create two thread. Work of software application is evenly distributed on 6 independent threads of execution created for the application. If no wait for resource is involved, Total CPU time is expected to be six times Elapsed real time.

See also

References


 
 
Learn More
keyboard interrupt (technology)
network accounting (technology)
CPU time (in marketing)

What is CPU burst time? Read answer...
What is CPU idle time? Read answer...
PC CPU over heating CPU at over 70c most of the time how can i fix this? Read answer...

Help us answer these
What is cpu kernel time?
What is the time line of the cpu?
What is cycle time in a CPU?

Post a question - any question - to the WikiAnswers community:

 

Copyrights:

Computer Desktop Encyclopedia. THIS DEFINITION IS FOR PERSONAL USE ONLY.
All other reproduction is strictly prohibited without permission from the publisher.
© 1981-2010 The Computer Language Company Inc.  All rights reserved.  Read more
Wikipedia. This article is licensed under the Creative Commons Attribution/Share-Alike License. It uses material from the Wikipedia article "CPU time" Read more