I want to calculate the time elapsed since the execution of take_forks() but the value of "b" and "end"are always 0.Why this happens?
Code:
clock_t start,end;
start=clock();//clocks before taking the forks
take_forks(i);
end=clock();//clocks after taking forks
double b=(double)(end-start)/(double)(CLOCKS_PER_SEC);
tmesos=tmesos+(b/counter)/n;
printf("waiting time is %f",b);
The value of start is also 0.On failure clock() returns -1 thus it did not failed. Is there another way to benchmark my function?
On Windows, QueryPerformanceFrequency() and QueryPerformanceCounter(). On Linux and similar, gettimeofday(). I think gettimeofday() works on OSX too but I'm not sure.
These functions have better resolution than clock().
Bookmarks