This is the mail archive of the libc-alpha@sources.redhat.com mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: a weird problem with clock


>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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]