-
January 4th, 2012, 06:58 AM
#1
problem with clock()
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);
-
January 4th, 2012, 07:31 AM
#2
Re: problem with clock()
And what is the value of start?
Victor Nijegorodov
-
January 4th, 2012, 09:00 AM
#3
Re: problem with clock()
CLOCKS_PER_SEC is usually 1000 on most systems. Perhaps the code you benchmarked ran fast enough and took less than 1ms?
-
January 6th, 2012, 07:16 AM
#4
Re: problem with clock()
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?
-
January 6th, 2012, 09:28 AM
#5
Re: problem with clock()
Originally Posted by killbill689
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().
-
January 6th, 2012, 04:08 PM
#6
Re: problem with clock()
I used gettimeofday() but i have the same problem
Code:
struct timeval start,end;
gettimeofday(&start,NULL);
take_forks(i);
gettimeofday(&end,NULL);
double b=(double)(end.tv_usec-start.tv_usec);
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|