From: H.G. Muller Date: Mon, 13 Feb 2012 12:37:28 +0000 (+0100) Subject: Let Fairy-Max print timing info X-Git-Tag: 4.8S~19 X-Git-Url: http://winboard.nl/cgi-bin?p=fairymax.git;a=commitdiff_plain;h=5b64a22e62beb2c9d21d5567993eb0f74b1fa074;hp=5dc87dcd0d60262efa7b5ce308b100371f72bc3d Let Fairy-Max print timing info Before and after search a time stamp are printed, and after the search the real and cpu time used for it. The time stamp can be compared to that of the opponent, to calculate communication delay through the GUI. --- diff --git a/fairymax.c b/fairymax.c index 5106ae1..931099a 100644 --- a/fairymax.c +++ b/fairymax.c @@ -32,13 +32,24 @@ #ifdef WIN32 # include +# define CPUtime 1000.*clock #else # include +# include +# include int GetTickCount() // with thanks to Tord { struct timeval t; gettimeofday(&t, NULL); return t.tv_sec*1000 + t.tv_usec/1000; } + double CPUtime() + { // get CPU time used by process, converted to 'MILLICLOCKS' + struct tms cpuTimes; + static int cps = 0; + if(!cps) cps = sysconf(_SC_CLK_TCK); + times(&cpuTimes); + return ((double)(cpuTimes.tms_utime + cpuTimes.tms_stime) * CLOCKS_PER_SEC * 1000)/cps; + } #endif int StartKey; @@ -522,7 +533,8 @@ int main(int argc, char **argv) { int Computer, MaxTime, MaxMoves, TimeInc, sec, i, j; char line[256], command[256], c, cc; - int m, nr; + int m, nr, hh; + double cpuT; FILE *f; if(argc>1 && sscanf(argv[1], "%d", &m)==1) @@ -555,6 +567,7 @@ int main(int argc, char **argv) /* the game have to be done in this time. */ /* If MaxMoves=1 any leftover time is lost*/ Ticks = GetTickCount(); + cpuT = CPUtime(); printf("# times @ %u\n", Ticks); m = MovesLeft<=0 ? 40 : MovesLeft; tlim = (0.6-0.06*(BW-8))*(TimeLeft+(m-1)*TimeInc)/(m+7); if(tlim>TimeLeft/15) tlim = TimeLeft/15; @@ -568,12 +581,14 @@ int main(int argc, char **argv) Computer = EMPTY; continue; } else UnderProm = -1; + m = GetTickCount() - Ticks; + printf("# times @ %u: real=%d cpu=%1.0f\n", m + Ticks, m, + (CPUtime() - cpuT)/CLOCKS_PER_SEC); printf("move "); printf("%c%c%c%c",'a'+(K&15),'0'+BH-(K>>4), 'a'+(L&15),'0'+BH-(L>>4)); if(prom)printf("%c",piecename[prom&15]+'a'-1); printf("\n"); - m = GetTickCount() - Ticks; /* time-control accounting */ TimeLeft -= m;