clock
Determine processor time used
Description
The clock function determines the amount of processor time used since the invocation of the calling process, measured in CLOCKS_PER_SEC of a second. The code below counts the number of seconds that passed while running some for loop.Example:
Example - Determine processor time used
Workings
#include <stdio.h> #include <time.h> #include <math.h> int main() { clock_t start = clock(); for (long i = 0; i < 100000000; ++i) exp(log((double)i)); clock_t finish = clock(); printf("It took %d seconds to execute the for loop.\n", (finish - start) / CLOCKS_PER_SEC); return 0; }
Solution
Output:
It took 23 seconds to execute the for loop.