clock_gettime extremely slow

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

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

Re: clock_gettime extremely slow

Post by hgm »

Ras wrote:Sounds like a lot of platform dependent stuff. However, the code that interfaces threaded stdin scanning with the search is portable - if only because it's a total hack on every platform. ;-)
Well, 'a lot' sounds like an exaggeration. Reading the clock is different between Windows API and POSIX anyway. So for polling I typically write my own Linux version of the Windows GetTickCount() in conditional Linux code. The same could be done for scheduling a timer event, I suppose.

Code: Select all

#ifdef WIN32
#  include <windows.h>
#  include <io.h>
   HANDLE process;
   DWORD thread_id;
#else
#  include <pthread.h>
#  include <signal.h>
#  define NO_ERROR 0
#  include <sys/time.h>
   int GetTickCount&#40;) // with thanks to Tord
   &#123; struct timeval t; gettimeofday&#40;&t, NULL&#41;; return t.tv_sec*1000 + t.tv_usec/1000; &#125;
#endif
An alternative is to put all API-referring code in a separate source file, of which you have one version for each platform, and let the make/configure process decide which to link. I think this is what Polyglot does.
elcabesa
Posts: 855
Joined: Sun May 23, 2010 1:32 pm

Re: clock_gettime extremely slow

Post by elcabesa »

nowadays c++ has platform indipendent code for clock management and threads.
http://en.cppreference.com/w/cpp/chrono

probably even latest c has some of those functionality.

my engine run on windows and linux and has on line of code dependent of the platform.