| delorie.com/archives/browse.cgi | search | 
| Mailing-List: | contact cygwin-help AT cygwin DOT com; run by ezmlm | 
| List-Subscribe: | <mailto:cygwin-subscribe AT cygwin DOT com> | 
| List-Archive: | <http://sourceware.org/ml/cygwin/> | 
| List-Post: | <mailto:cygwin AT cygwin DOT com> | 
| List-Help: | <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs> | 
| Sender: | cygwin-owner AT cygwin DOT com | 
| Mail-Followup-To: | cygwin AT cygwin DOT com | 
| Delivered-To: | mailing list cygwin AT cygwin DOT com | 
| To: | cygwin AT cygwin DOT com | 
| From: | "Alex Vinokur" <alexvn AT connect DOT to> | 
| Subject: | What does clock() return? | 
| Date: | Thu, 8 Jul 2004 07:01:31 +0300 | 
| Lines: | 106 | 
| Message-ID: | <cciguv$e7o$1@sea.gmane.org> | 
| X-Complaints-To: | usenet AT sea DOT gmane DOT org | 
| X-Gmane-NNTP-Posting-Host: | 82.166.218.119 | 
| X-Newsreader: | Microsoft Outlook Express 6.00.2800.1409 | 
Here is an article http://groups.google.com/groups?selm=2l2ucgF7jv50U1%40uni-berlin.de
from http://groups.google.com/groups?group=microsoft.public.vc.language
"Victor Bazarov" <v DOT Abazarov AT comAcast DOT net> wrote in message news:%23gH7pzEZEHA DOT 992 AT TK2MSFTNGP10 DOT phx DOT gbl...
> Is it a known issue that in VC++ RTL the function 'clock()'
> reports the wall clock instead of CPU time used?  I ran this
> test program on Windows and Unix:
> -----------------------------------------
> #include <iostream>
> #include <ctime>
>
> using namespace std;
>
> int main()
> {
>      time_t t0 = time(0);
>      clock_t c0 = clock();
>
>      for (int i = 0; i < 10; ++i)
>      {
>          cout << "push > " << flush;
>          char a;
>          cin >> a;
>          cout << endl;
>      }
>
>      cout << "Difference in wall clock is "
>           << difftime(time(0), t0) << endl;
>      cout << "Difference in CPU ticks is "
>           << double(clock() - c0) / CLOCKS_PER_SEC << endl;
>
>      return 0;
> }
> -------------------------------------------
> and got very similar values on Windows and quite different
> values on Unix.  It seems that on Windows it just takes the
> time() at the beginning and then 'clock' simply takes the
> difference between current time and the stored value and
> multiplies it with CLOCKS_PER_SEC...
>
> I know of GetProcessTimes() function, but couldn't 'clock()'
> be implemented to use it?
>
> Thanks.
>
> Victor
Windows 2000.
The problem is not only with VC++ RTL.
The program has been compiled:
* with Microsoft C++ 13.00.9466 for 80x86
  cl /EHsc program.cpp -o a_ms.exe
* with gcc version 3.3.1 (cygming special)
   g++ -mno-cygwin -o a_mgw program.cpp     // Use the Mingw32 interface
   g++ -o a_cyg program.cpp  // Cygwin
Here are results:
$ a_ms
[---omitted---]
Difference in wall clock is 11
Difference in CPU ticks is 11.847
$ a_mgw
[---omitted---]
Difference in wall clock is 10
Difference in CPU ticks is 10.925
$ a_cyg
[---omitted---]
Difference in wall clock is 9
Difference in CPU ticks is 0.03
Here are DLLs:
a_ms.exe
  C:\WINNT\system32\KERNEL32.dll
    C:\WINNT\system32\NTDLL.DLL
a_mgw.exe
  C:\WINNT\system32\msvcrt.dll
    C:\WINNT\system32\KERNEL32.dll
      C:\WINNT\system32\NTDLL.DLL
a_cyg.exe
  C:\cygwin\bin\cygwin1.dll
    C:\WINNT\system32\ADVAPI32.DLL
      C:\WINNT\system32\NTDLL.DLL
      C:\WINNT\system32\KERNEL32.DLL
      C:\WINNT\system32\RPCRT4.DLL
It seems that the problem is in DLLs (?).
-- 
   Alex Vinokur
     http://mathforum.org/library/view/10978.html
     http://sourceforge.net/users/alexvn
--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/
| webmaster | delorie software privacy | 
| Copyright © 2019 by DJ Delorie | Updated Jul 2019 |