Execution time

How do I get the execution time of a program in Windows?

CLOCKS_PER_SEC is a constant which is declared in <time.h>. To get the CPU time used by a task within a C application, use:

clock_t begin, end;

double time_spent;

begin = clock();

/* here, do your time-consuming job */

end = clock();

time_spent = (double)(end - begin) / CLOCKS_PER_SEC;

Note that this returns the time as a floating point type. This can be more precise than a second (e.g. you measure 4.52 seconds). Precision depends on the architecture; on modern systems you easily get 10ms or lower, but on older Windows machines (from the Win98 era) it was closer to 60ms.
check this link http://stackoverflow.com/questions/5248915/execution-time-of-c-program

clock() is standard C; it works “everywhere”. There are system-specific functions, such as getrusage() on Unix-like systems.

Java’s System.currentTimeMillis() does not measure the same thing. It is a “wall clock”: it can help you measure how much time it took for the program to execute, but it does not tell you how much CPU time was used. On a multitasking systems (i.e. all of them), these can be widely different.

3 Likes