Buy the book!
|[ < ]||[ > ]||[ << ]||[ Up ]||[ >> ]||[Top]||[Contents]||[Index]||[ ? ]|
To get a process' CPU time, you can use the
clock function. This
facility is declared in the header file `time.h'.
In typical usage, you call the
clock function at the beginning
and end of the interval you want to time, subtract the values, and then
CLOCKS_PER_SEC (the number of clock ticks per second)
to get processor time, like this:
#include <time.h> clock_t start, end; double cpu_time_used; start = clock(); ... /* Do the work. */ end = clock(); cpu_time_used = ((double) (end - start)) / CLOCKS_PER_SEC;
Do not use a single CPU time as an amount of time; it doesn't work that way. Either do a subtraction as shown above or query processor time directly. See section 21.3.2 Processor Time Inquiry.
Different computers and operating systems vary wildly in how they keep track of CPU time. It's common for the internal processor clock to have a resolution somewhere between a hundredth and millionth of a second.
clockfunction. POSIX requires that this value be one million independent of the actual resolution.
clockfunction. Values of type
clock_tare numbers of clock ticks.
clockreturns the value
|webmaster||delorie software privacy|
|Copyright © 2003 by The Free Software Foundation||Updated Jun 2003|