Names specified here
Name Description Notes Source Availability
CLOCKS_PER_SEC Granularity of execution-time clock M <time.h> C89 C90 C95 C99 C11
clock() Get execution time (·) <time.h> C89 C90 C95 C99 C11
clock_t Execution-time type T <time.h> C89 C90 C95 C99 C11
#include <time.h>
clock_t clock(void);

The function clock returns the current time related to the start of the program's execution. Divide the result by CLOCKS_PER_SEC, which is an arithmetic constant, to get that time in seconds. clock_t is a real type. The value (clock_t) -1 is returned if program duration is unavailable.

The initial value is not necessarily zero. You should call clock close to the start of the program's execution (early in main) to obtain an epoch closely representing the start of the program, and subtract it from subsequent values before dividing. For example:

clock_t zero_time;

int main(void)
{
  zero_time = clock();

  . . .
}

// Later…
double runtime = (clock() - zero_time) / CLOCKS_PER_SEC;

CHaR
Sitemap Supported
Site format updated 2024-06-05T22:37:07.391+0000
Data updated 1970-01-01T00:00:00.000+0000
Page updated 2022-06-17T21:43:05.000+0000