hgm wrote:Does anyone know how to get the CPU time used by the current process in Windows? I thought that clock() was supposed to do that, but it seems to always return a value identical to the wall-clock time from GetTickCount().
could you make a Fruit 2.1 Windows compile for me that prints the real time and the user time? I don't manage to compile it with gcc in -mno-cygwin mode, it produces tons of error messages. (On Linux it compiled fine, and cpu_now() and real_now() also worked with good precision.) What I need is a version that prints
startTime = WallClockTime(); // time stamp (millisec)
cpuTime = CPUtime(); // Total CPU used upto now (millisec)
printf("info string times @ %u\n", startTime);
immediately after it receives a "go" command (this code is in protocol.cpp), and
stopTime = WallClockTime(); // time stamp
cpuTime = CPUtime() - cpuTime; // Consumed CPU time
printf("info string times @ %u: real=%u cpu=%u\n", stopTime, stopTime - startTime, cpuTime);
just before it sends "bestmove". (Also in protocol.cpp.)
I have written a small program that extracts such messages from the debug file, and calculates from them the delay between sending a move and the opponent receiving it, and CPU time stolen by the GUI.
could you make a Fruit 2.1 Windows compile for me that prints the real time and the user time? I don't manage to compile it with gcc in -mno-cygwin mode, it produces tons of error messages. (On Linux it compiled fine, and cpu_now() and real_now() also worked with good precision.) What I need is a version that prints
startTime = WallClockTime(); // time stamp (millisec)
cpuTime = CPUtime(); // Total CPU used upto now (millisec)
printf("info string times @ %u\n", startTime);
immediately after it receives a "go" command (this code is in protocol.cpp), and
stopTime = WallClockTime(); // time stamp
cpuTime = CPUtime() - cpuTime; // Consumed CPU time
printf("info string times @ %u: real=%u cpu=%u\n", stopTime, stopTime - startTime, cpuTime);
just before it sends "bestmove". (Also in protocol.cpp.)
I have written a small program that extracts such messages from the debug file, and calculates from them the delay between sending a move and the opponent receiving it, and CPU time stolen by the GUI.
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
static void
__winnt_cpu_time (long *sec, long *usec)
{
union {
FILETIME ft;
unsigned long long ulltime;
} kernel_time, user_time;
FILETIME unused1, unused2;
unsigned long long total_time;
/* No support for Win9x. The high order bit of the DWORD
returned by GetVersion is 0 for NT and higher. */
if (GetVersion () >= 0x80000000)
{
*sec = -1;
*usec = 0;
return;
}
/* The FILETIME structs filled in by GetProcessTimes represent
time in 100 nanosecond units. */
GetProcessTimes (GetCurrentProcess (), &unused1, &unused2,
&kernel_time.ft, &user_time.ft);
total_time = (kernel_time.ulltime + user_time.ulltime)/10;
*sec = total_time / 1000000;
*usec = total_time % 1000000;
}
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.
Jim, could you make another Win-32 compile of Fruit for me? I have now increased the precision of the timers to 0.1 msec, for both wall-clock and CPU time.
I plan to distribute this version of Fruit 2.1 with the WinBoard binary package, and perhaps also make a separate 'timing kit' for people wanting to evaluate GUI performance, with this Fruit, a similarly adapted Fairy-Max and a tool to extract the timing lines from a debug file, and print the timing stats.
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.
/***
*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 +
(((unsigned __int64)ct.dwHighDateTime) << 32);
/* calculate the elapsed number of 100 nanosecond units */
current_tics -= start_tics;
/* return number of elapsed milliseconds */
return (clock_t)(current_tics / 10000);
}