The clock function returns the amount of time spent in your program start. The clock function has no parameters, and returns its value in as a clock_t type, which codifies information that is dependent on the processor used.

Using the returned value

To transform the clock_t value into the number of seconds spent by the program, one needs to divide the returned value by the constant CLOCKS_PER_SEC (this function is defined in time.h).


The following code shows an example of the clock function:

#include <stdio.h>
#include <time.h>

int main()
        clock_t t;
        t = clock();
        printf("the ellapsed time is %lf\n", (double)t/CLOCKS_PER_SECOND);
        return 0;
Article created on 2008-08-19 21:47:51

Post a comment