CPU time in Windows

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

User avatar
hgm
Posts: 27787
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: CPU time in Windows

Post by hgm »

Wow, you are fast! :D Thanks!
rbarreira
Posts: 900
Joined: Tue Apr 27, 2010 3:48 pm

Re: CPU time in Windows

Post by rbarreira »

Daniel Shawul wrote:I am surprized though why unix clock() measures the cpu time. C++ seems to define clock() as a measure of wall clock time http://www.cplusplus.com/reference/clib ... ime/clock/. It is mentioned that the reference could be different on different systems but nothing about some systems excluding I/O time.
Actually that page is even more confusing, as it talks about "processing times" as well.
Daniel Shawul
Posts: 4185
Joined: Tue Mar 14, 2006 11:34 am
Location: Ethiopia

Re: CPU time in Windows

Post by Daniel Shawul »

Actually that page is even more confusing, as it talks about "processing times" as well.
That page is consistent with msvc implementation. OTOH glibc's implementation is weird for me.

Code: Select all

/***
*clock_t clock() - Return the processor time used by this process.
*
*Purpose:
*       This routine calculates how much time the calling process
*       has used.  At startup time, startup calls __inittime which stores
*       the initial time.  The clock routine calculates the difference
*       between the current time and the initial time.
*
*       Clock must reference _cinitime so that _cinitim.asm gets linked in.
*       That routine, in turn, puts __inittime in the startup initialization
*       routine table.
*
*Entry:
*       No parameters.
*       itime is a static structure of type timeb.
*
*Exit:
*       If successful, clock returns the number of CLK_TCKs (milliseconds)
*       that have elapsed.  If unsuccessful, clock returns -1.
*
*Exceptions:
*       None.
*
*******************************************************************************/

clock_t __cdecl clock (
        void
        )
{
        unsigned __int64 current_tics;
        FILETIME ct;

        GetSystemTimeAsFileTime( &ct );

        current_tics = (unsigned __int64)ct.dwLowDateTime +
                       ((&#40;unsigned __int64&#41;ct.dwHighDateTime&#41; << 32&#41;;

        /* calculate the elapsed number of 100 nanosecond units */
        current_tics -= start_tics;

        /* return number of elapsed milliseconds */
        return &#40;clock_t&#41;&#40;current_tics / 10000&#41;;
&#125;