Re: clock(3) non-functional?
On Tue, 2014-07-01 at 14:04 +0200, Samuel Thibault wrote:
> Svante Signell, le Tue 01 Jul 2014 12:41:47 +0200, a écrit :
> > On Sun, 2014-06-29 at 22:56 +0200, Samuel Thibault wrote:
> > > Hello,
> > >
> > > Svante Signell, le Sun 29 Jun 2014 16:35:42 +0200, a écrit :
> > > > Looking at libsamplerate test problems, I found that clock(3) used
> > > > there is not reliable. Strange results are obtained on too Linux with a
> > > > simple test program.
> > >
> > > What do you mean by "strange"? The output I get
> > >
> > > $ ./test
> > > start = 3870
> > > end = 3910
> > > cpu_time_used = 0.000040
> >
> > I get:
> > gcc -g -Wall test_clock.c
> > ./a.out
> > start = 0
> > end = 0
> > cpu_time_used = 0.000000
>
> Well, yes, as I said sleep() doesn't consume CPU while sleeping, so
> clock() would only account the small overhead for starting the sleep,
> which is very small. Since the granularity is 1/100th second on the
> Hurd, that eventually amounts to zero.
Why are the integers start and end zero?
Consider the following program:
#define _GNU_SOURCE 1
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main(void)
{
clock_t start, end;
double cpu_time_used;
int i = 0;
double a = 1;
start = clock();
printf("start = %ld\n", start);
for (i=0; i < 30000000; i++)
a /= 1.001;
end = clock();
printf("end = %ld\n", end);
cpu_time_used = end - start;
cpu_time_used = ((double) (end - start)) / CLOCKS_PER_SEC;
printf("cpu_time_used = %f\n", cpu_time_used);
return 0;
}
on Linux I get:
start = 1110
end = 2162016
cpu_time_used = 2.160906
and on Hurd:
start = 0
end = 423
cpu_time_used = 0.000423
I don't believe Hurd is more than 5000 times faster than Linux!
Reply to: