I've been trying to measure time elapsed in a C program using the clock function, but whenever I try to printf any clock values I'm getting back 0. For example:
clock_t time1, time2;
time1 = clock();
printf("Time 1 is %d.\n", (int)time1);
sleep(2);
time2 = clock();
printf("Time 2 is %d.\n", (int)time2);
In both cases, time1 and time2 print out as 0. I have a feeling it's because I'm using the wrong type in the printf, but every type I've seen doesn't seem to work for me. I've used %Lf, %ld, %f. Can anyone else spot a problem here?
EDIT: I tried most of the types mentioned in this thread: What’s the correct way to use printf to print a clock_t? I even tried uintmax_t, but without the ability to print p1 and p2, I don't know how to verify if it's a type issue or if clock isn't returning the adequate value.