X-Authentication-Warning: delorie.com: mail set sender to djgpp-bounces using -f From: "Alex Vinokur" Newsgroups: comp.os.msdos.djgpp Subject: Microsoft clock() Date: Thu, 8 Jul 2004 13:34:54 +0300 Lines: 157 Message-ID: <2l4majF8iuhdU1@uni-berlin.de> X-Trace: news.uni-berlin.de T8INyx8dc95hVhJG33tbCgfrigP0B2Jqs3ghV0ICo8X4G2kZw= X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1409 X-Mimeole: Produced By Microsoft MimeOLE V6.00.2800.1409 To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com Victor Bazarov test at http://groups.google.com/groups?selm=%23gH7pzEZEHA.992%40TK2MSFTNGP10.phx.gbl detected problematic behavior of clock() on Microsoft Windows. That concerns gpp (DJGPP) too. Note. g++ (Cygwin) generates valid CPU used time. ============ Windows 2000 ============ --------- C++ code : foo.cpp : BEGIN --------- #include #include #include #include using namespace std; int main() { time_t start_time, end_time; clock_t start_clock, end_clock; clock_t diff_clock; time_t diff_time; start_time = time(NULL); if (start_time == time_t(-1)) { cout << "Unable to get start time()" << endl; return 1; } start_clock = clock(); if (start_clock == clock_t(-1)) { cout << "Unable to get start clock()" << endl; return 1; } sleep (3); end_time = time(NULL); if (end_time == time_t(-1)) { cout << "Unable to get end time()" << endl; return 1; } end_clock = clock(); if (end_clock == clock_t(-1)) { cout << "Unable to get end clock()" << endl; return 1; } // ------------------------- assert (!(start_time == (time_t)-1)); assert (!(end_time == (time_t)-1)); assert (!(start_clock == (clock_t)-1)); assert (!(end_clock == (clock_t)-1)); // ------------------------- diff_time = end_time - start_time; diff_clock = end_clock - start_clock; cout << endl; cout << "time : " << "start = " << start_time << " sec" << ", end = " << end_time << " sec" << endl; cout << "time : " << "elapsed (wall clock) time = " << double (diff_time) << " sec" << endl; cout << endl; cout << "clock : " << "start = " << start_clock << " ticks" << ", end = " << end_clock << " ticks" << endl; cout << "clock : " << "cumulative processor time = " << double(diff_clock)/CLOCKS_PER_SEC << " sec" << endl; return 0; } --------- C++ code : foo.cpp : END ----------- --------- Compilation & Run : BEGIN --------- $ gpp -v Reading specs from c:/djgpp/lib/gcc-lib/djgpp/3.32/specs Configured with: /devel/gnu/gcc/3.3/gnu/gcc-3.32/configure i586-pc-msdosdjgpp -- prefix=/dev/env/DJDIR --disable-nls Thread model: single gcc version 3.3.2 $ gpp foo.cpp -o dj.exe $ dj time : start = 1089292733 sec, end = 1089292736 sec time : elapsed (wall clock) time = 3 sec clock : start = 0 ticks, end = 275 ticks clock : cumulative processor time = 3.02198 sec $ g++ -v Reading specs from /usr/lib/gcc-lib/i686-pc-cygwin/3.3.1/specs Configured with: /GCC/gcc-3.3.1-3/configure --with-gcc --with-gnu-ld --with-gnu- as --prefix=/usr --exec-prefix=/usr --sysconfdir=/etc --libdir=/usr/lib --libexe cdir=/usr/sbin --mandir=/usr/share/man --infodir=/usr/share/info --enable-langua ges=c,ada,c++,f77,pascal,java,objc --enable-libgcj --enable-threads=posix --with -system-zlib --enable-nls --without-included-gettext --enable-interpreter --enab le-sjlj-exceptions --disable-version-specific-runtime-libs --enable-shared --dis able-win32-registry --enable-java-gc=boehm --disable-hash-synchronization --verb ose --target=i686-pc-cygwin --host=i686-pc-cygwin --build=i686-pc-cygwin Thread model: posix gcc version 3.3.1 (cygming special) $ g++ foo.cpp -o cyg.exe $ cyg time : start = 1089281988 sec, end = 1089281991 sec time : elapsed (wall clock) time = 3 sec clock : start = 20 ticks, end = 30 ticks clock : cumulative processor time = 0.01 sec --------- Compilation & Run : END ----------- So, one can see that gpp and g++ generate quite different "cumulative processor time". It seems that "cumulative processor time" generated by g++ (Cygwin) is more believable. -- Alex Vinokur http://mathforum.org/library/view/10978.html http://sourceforge.net/users/alexvn