ProgramThe timing function is often usedCodeTherefore, the clock () function is often used, which is included in the header file of time. h.
The timing function is based on the clock_t data type and can be found in the time. h file:
/* Define the implementation defined time type */</P> <p> # ifndef _ time_t_defined <br/> typedef long time_t; /* Time Value */<br/> # DEFINE _ time_t_defined/* avoid multiple Def's of time_t */<br/> # endif </P> <p> # ifndef _ clock_t_defined <br/> typedef long clock_t; <br/> # DEFINE _ clock_t_defined <br/> # endif
Clock_t actually refers to the Data Type of long integer.
The specific usage of the timing function is as follows:
# Include <stdio. h> <br/> # include <time. h> </P> <p> int main () <br/>{< br/> clock_t start, finish; <br/> Start = clock (); </P> <p> int counter = 0; <br/> for (INT I = 0; I <1000000; I ++) <br/>{< br/> counter ++; <br/>}</P> <p> finish = clock (); </P> <p> printf ("the program running time is % d seconds/N", (finish-Start)/clocks_per_sec ); <br/>/* Clock ticks macro-ANSI version */<br/> // clocks_per_sec at time. <br/> // # define clocks_per_sec 1000 <br/> // describe clock () the return value is millisecond </P> <p> getchar (); <br/> return 0; <br/>}