
#include <time.h> clock_t clock(void);
clock returns the amount of processor time used by the program
relative to some base point. The amount of processor time used between
two calls is indicated by the difference between the values returned by
the two calls to clock in the same program.
The value returned is of type clock_t. The value returned is in
fractions of a second, where a value of CLOCKS_PER_SEC represents
one second of processor time. (clock_t and CLOCKS_PER_SEC
are defined in <time.h>.) In this implementation, clock_t
is defined as a double and CLOCKS_PER_SEC is 1.0.
clock returns the number of seconds since the base time. If an
accurate value cannot be returned, (clock_t)-1 is returned.
clock is of relatively low accuracy and may
depend on the extent of other system activity. Values returned by
clock are likely to be inconsistent from one execution of a program to
another.
CLOCKS_PER_SEC as a
scale factor when using the value returned by clock. Also, you
should declare variables that contain clock values as clock_t
because many implementations define this type as long int or
unsigned long int.
clock is the first call; that is, the
first call of clock in an MVS program always returns 0.0.
If the program calls the system function, processor time
subsequently used by invoked programs is not included in the value
returned by clock.
Under CMS, the base point for clock is the total processor time
(TOTCPU) as returned by DIAGNOSE X'0C'. If the accumulated time is
reset by the system operator after a call to clock, clock
returns - 1.0 thereafter because the amount of the processor time
used can no longer be determined.
#include <time.h>
#include <math.h>
#include <stdio.h>
main()
{
clock_t start, end;
double index;
/* time used before start of computation */
start = clock();
for(index = 1.0; index <= 1000.0; ++index)
(void)log(index);
end = clock();
printf("Processor time used = %g seconds.n",
(end - start) / CLOCKS_PER_SEC);
}
alarm, time
Copyright (c) 1998 SAS Institute Inc. Cary, NC, USA. All rights reserved.