clock
clock_t clock ( void ); | time.h |
cplusplus.com |
Return number of clock ticks since process start.
Returns the number of clock ticks elapsed.
A macro constant called CLK_TCK
defines the relation betwen clock tick and second (clock ticks per second).
Parameters.
Return Value.
The number of clock ticks elapsed since start.
clock_t type is defined by default as long int by most compilers.
Portability.
Defined in ANSI-C.
Example.
/* clock example: countdown */
#include <stdio.h>
#include <time.h>
void wait ( int seconds )
{
clock_t endwait;
endwait = clock () + seconds * CLK_TCK ;
while (clock() < endwait) {}
}
main ()
{
int n;
printf ("Starting countdown...\n");
for (n=10; n>0; n--)
{
printf ("%d\n",n);
wait (1);
}
printf ("FIRE!!!\n");
return 0;
}
Output:
Starting countdown...
10
9
8
7
6
5
4
3
2
1
FIRE!!!