This is the mail archive of the
libc-alpha@sources.redhat.com
mailing list for the glibc project.
Re: a weird problem with clock
- From: Peter Barada <peter at the-baradas dot com>
- To: tangyan at ict dot ac dot cn
- Cc: libc-alpha at sources dot redhat dot com
- Date: Wed, 29 Sep 2004 00:51:05 -0400 (EDT)
- Subject: Re: a weird problem with clock
- References: <32841.159.226.40.187.1096425266.squirrel@159.226.40.187>
>int main()
>{
> int i, sum;
> clock_t start, end;
>
> start = clock();
>
> for (i = 0; i < 10000; i++) {
> sum += i;
> }
>
> end = clock();
>
> printf("start: %ld, end: %ld\n", start, end);
>
> return 0;
>}
>--------------------------------
>The problem is in my box the output is ALWAYS "start: 0, end: 0".
>
Look at the compiled code. The optimizer has probably converted this
to something like:
int main()
{
clock_t start, end;
start = clock();
end = clock();
printf("start: %ld, end: %ld\n", start, end);
return 0;
}
since the optimzer determines that the loop doesn't do any useful work
and removed it.
--
Peter Barada
peter@the-baradas.com