#import <stdio.h>
#import <time.h>
int main (void) {
printf("Clock ticks per second: %d\n", CLOCKS_PER_SEC);
double check = clock();
int timex = time(NULL);
for (int x = 0; x <= 500000; x++) {
printf(".");
}
puts("\n");
printf("Total Time by Clock: %7.7f\n", (clock() - check) / CLOCKS_PER_SEC );
printf("Total Time by Time: %d\n", time(NULL) - timex);
getchar();
}
When I execute the above code, I get results such as:
Total time by hours: 0.0108240
Total time by time: 12
I would like clock () to represent the number as close to time as possible.
The total time stated above was done on a macbook, however the code works fine on my laptop (windows).
The macro CLOCKS_PER_SECOND returns 1000 on a PC, 1,000,000 on a MAC.
source
share