This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC 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()


tangyan@ict.ac.cn wrote:
> Hello, everyone.  I have a weird problem with clock() in glibc and I have
> tried my best to solve it myself but it still doesn't work.
> 
> My little program is as following:
> --------------------------------
> #include <time.h>
> #include <stdio.h>
> 
> 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".
> 
> Environment:
> $uname -a
> =>
> ---------------------------
> Linux client135 2.4.20-8smp #1 SMP Thu Mar 13 17:45:54 EST 2003 i686 i686
> i386 GNU/Linux
> ---------------------------
> OS: Redhat 9.0
> ---------------------------
> $cat /proc/cpuinfo
> =>
> ---------------------------
> processor       : 1
> vendor_id       : GenuineIntel
> cpu family      : 15
> model           : 2
> model name      : Intel(R) Pentium(R) 4 CPU 2.60GHz
> stepping        : 9
> cpu MHz         : 2593.519
> cache size      : 512 KB
> physical id     : 0
> siblings        : 2
> fdiv_bug        : no
> hlt_bug         : no
> f00f_bug        : no
> coma_bug        : no
> fpu             : yes
> fpu_exception   : yes
> cpuid level     : 2
> wp              : yes
> flags           : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca
> cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm
> bogomips        : 5177.34
> --------------------------
> $ gcc -v
> =>
> ----------------------------
> Reading specs from /usr/lib/gcc-lib/i386-redhat-linux/3.2.2/specs
> Configured with: ../configure --prefix=/usr --mandir=/usr/share/man
> --infodir=/usr/share/info --enable-shared --enable-threads=posix
> --disable-checking --with-system-zlib --enable-__cxa_atexit
> --host=i386-redhat-linux
> Thread model: posix
> gcc version 3.2.2 20030222 (Red Hat Linux 3.2.2-5)
> ----------------------------
> 
> The output of `ldd' on the `test' generated by "gcc test.c -o test" is,
> ------------------------------
> libc.so.6 => /lib/tls/libc.so.6 (0x42000000)
> /lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x40000000)
> ------------------------------
> 
> What's wrong with my little program?
> I just do all the things exactly followed the `time & data' chapter in
> glibc manual, but the output is always ZERO.  The return value of clock()
> is 0, so it seems no error (-1) occurs.  But why it always return 0?
> 
> Thank you very much!
> 
> BHW: I have not subscribe this mailing list, so anyone having some idea
> about this problem please replys directly to my mailbox, thanks.
> 
> 
> 

I get the same as you. You just need to increase the number of
iterations. 10 million or so should be enough to start getting a
non-zero value. You'll probably find anything that takes less than .01
seconds to run fails to register a clock count.

Cheers,
Rob

-- 
Any emails containing attachments will be deleted from my ISP's mail
server before I even get to see them. If you wish to email me an
attachment, please provide advance warning so that I can make the
necessary arrangements.


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