Let Fairy-Max print timing info
authorH.G. Muller <h.g.muller@hccnet.nl>
Mon, 13 Feb 2012 12:37:28 +0000 (13:37 +0100)
committerH.G. Muller <h.g.muller@hccnet.nl>
Mon, 13 Feb 2012 12:40:16 +0000 (13:40 +0100)
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.

fairymax.c

index 5106ae1..931099a 100644 (file)
 \r
 #ifdef WIN32 \r
 #    include <windows.h>\r
+#    define CPUtime 1000.*clock\r
 #else\r
 #    include <sys/time.h>\r
+#    include <sys/times.h>\r
+#    include <unistd.h>\r
      int GetTickCount() // with thanks to Tord\r
      { struct timeval t;\r
        gettimeofday(&t, NULL);\r
        return t.tv_sec*1000 + t.tv_usec/1000;\r
      }\r
+     double CPUtime()\r
+     {  // get CPU time used by process, converted to 'MILLICLOCKS'\r
+       struct tms cpuTimes;\r
+       static int cps = 0;\r
+       if(!cps) cps = sysconf(_SC_CLK_TCK);\r
+       times(&cpuTimes);\r
+       return ((double)(cpuTimes.tms_utime + cpuTimes.tms_stime) * CLOCKS_PER_SEC * 1000)/cps;\r
+     }\r
 #endif\r
 \r
 int StartKey;\r
@@ -522,7 +533,8 @@ int main(int argc, char **argv)
 {\r
         int Computer, MaxTime, MaxMoves, TimeInc, sec, i, j;\r
         char line[256], command[256], c, cc;\r
-        int m, nr;\r
+        int m, nr, hh;\r
+        double cpuT;\r
         FILE *f;\r
 \r
         if(argc>1 && sscanf(argv[1], "%d", &m)==1)\r
@@ -555,6 +567,7 @@ int main(int argc, char **argv)
                         /* the game have to be done in this time. */\r
                         /* If MaxMoves=1 any leftover time is lost*/\r
                         Ticks = GetTickCount();\r
+                        cpuT = CPUtime(); printf("# times @ %u\n", Ticks);\r
                         m = MovesLeft<=0 ? 40 : MovesLeft;\r
                         tlim = (0.6-0.06*(BW-8))*(TimeLeft+(m-1)*TimeInc)/(m+7);\r
                         if(tlim>TimeLeft/15) tlim = TimeLeft/15;\r
@@ -568,12 +581,14 @@ int main(int argc, char **argv)
                                  Computer = EMPTY;\r
                                  continue;\r
                             } else UnderProm = -1;\r
+                            m = GetTickCount() - Ticks;\r
+                            printf("# times @ %u: real=%d cpu=%1.0f\n", m + Ticks, m,\r
+                                      (CPUtime() - cpuT)/CLOCKS_PER_SEC);\r
                             printf("move ");\r
                             printf("%c%c%c%c",'a'+(K&15),'0'+BH-(K>>4),\r
                                           'a'+(L&15),'0'+BH-(L>>4));\r
                            if(prom)printf("%c",piecename[prom&15]+'a'-1);\r
                             printf("\n");\r
-                            m = GetTickCount() - Ticks;\r
 \r
                             /* time-control accounting */\r
                             TimeLeft -= m;\r