The header file time.h defines a number of library functions which can be
used to assess how much CPU time a C program consumes during execution. The simplest
such function is called clock(). A call to this function, with no argument,
will return the amount of CPU time used so far by the calling program. The time
is returned in a special data type, clock_t, defined in time.h.
This
time must be divided by CLOCKS_PER_SEC, also defined in time.h, in order
to covert it into seconds. The ability to measure how much CPU time a given
code consumes is useful in scientific programming: e.g., because it allows the effectiveness
of the various available compiler optimization flags to be determined. Optimization
usually (but not always!) speeds up the execution of a program.
However, over aggressive
optimization can
often slow a program down again.

The program listed below illustrates the
simple use of the clock() function. The program compares the CPU
time required to raise a double to the fourth power via a direct calculation
and via a call to the pow() function. Actually, both operations are performed
a million times and the elapsed CPU time is then divided by a million.

Clearly, evaluating a fourth power using the pow() function is a
lot more expensive than the direct calculation. Hence, as has already
been mentioned, the pow() function should not be used to raise
floating point quantities to small integer powers.