a weird problem with clock

Peter Barada peter@the-baradas.com
Wed Sep 29 04:51:00 GMT 2004


>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



More information about the Libc-alpha mailing list