Hi all,
Here's the problem I have. clock() call returns 0 no matter when I call it....
Code:
#include <time.h>
#include <stdio.h>
#include <math.h>
int main()
{
volatile double n, i, x;
clock_t time1, time2, time3;
int j;
// while (time1 < 1)
time1 = clock();
for (i = 0; i < 100000; i++)
{
n = sqrt(i);
x = n + n;
}
// while (time2 < 1)
time2 = clock();
for (j = 0; j < 500000; j++)
{
n = j*j*j;
x = n / j;
}
// while (time3 < 30000)
time3 = clock();
printf("%ld %ld %ld\n", time1, time2, time3);
return 0;
}
Code compiled with -O0, but output is just 0 0 0. If I uncomment the whiles, it spews out random numbers, something like: 6509390 134518684 30000.
I have a workaround that uses ftime(), but I'm really troubled by the fact that clock() doesn't work. Am I missing something completely obvious here?
By the way, this is on fedora10, gcc compiler.
Thanks