clock_t clock (void);
Calculates the processor time used by the calling process
Head file is <time.h>
Return Value
Clock returns the number of clock ticks of elapsed processor time. The returned value
is the product of the amount of has elapsed since the start of a process and
The value of the CLOCKS_PER_SEC constant. If The amount of elapsed is
Unavailable, the function returns–1, cast as a clock_t.
Remarks
The clock function tells how much processor time the calling process has used. The
Time in seconds was approximated by dividing the clock return value by the value of the
CLOCKS_PER_SEC constant. In other words, clock returns the number of
Processor timer ticks that have elapsed. A timer tick is approximately equal to
1/clocks_per_sec second. In versions of Microsoft C before 6.0, the
CLOCKS_PER_SEC constant was called CLK_TCK.
Copy Code code as follows:
/* CLOCK. C:this example prompts for how long
* The program are to run and then continuously
* Displays the elapsed time for that period.
*/
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
void sleep (clock_t wait);
void Main (void)
{
Long i = 600000000L;
clock_t start, finish;
Double duration;
/* Delay for a specified time. */
printf ("Delay for three seconds\n");
Sleep ((clock_t) 3 * clocks_per_sec);
printf ("done!\n");
/* Measure The duration of an event. */
printf ("Time to does%ld empty loops is", i);
start = Clock ();
while (i--)
finish = Clock ();
Duration = (double) (finish-start)/clocks_per_sec;
printf ("%2.1f seconds\n", duration);
}
/* Pauses for a specified number of milliseconds. */
void sleep (clock_t wait)
{
clock_t goal;
Goal = wait + clock ();
while (Goal > clock ())
}//sleep