Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: To Bob- how do you compute cpuload?

Author: Jeremiah Penery

Date: 17:56:46 03/24/03

Go up one level in this thread


On March 24, 2003 at 11:49:51, Peter Fendrich wrote:

>We have a discussion in the WinBoard forum about how to compute cpuload and
>Crafty is mentioned as good example.
>
>How do you compute it in Crafty under the windows environment?

It's in utility.c.  Here is the relevant code:

unsigned int ReadClock(TIME_TYPE type) {
  HANDLE hThread;
  FILETIME ftCreate, ftExit, ftKernel, ftUser;
  unsigned int cputime;
  BITBOARD tUser64;

  switch (type) {
    case cpu:
      hThread = GetCurrentThread();
      if (GetThreadTimes(hThread, &ftCreate, &ftExit, &ftKernel, &ftUser)) {
        tUser64 = *(BITBOARD *)&ftUser;
        cputime=(unsigned int)(tUser64/100000);
      }
      return(cputime);
    case elapsed:
      return( (unsigned int) GetTickCount()/10);
    default:
      return( (unsigned int) GetTickCount()/10);
  }
}

It's probably not the fastest possible, but it's the only way I could find to
get accurate thread timing on Windows.  Of course, it shouldn't be called all
that often, so the speed isn't critical.  It may also need a couple of
Windows-specific #includes, but I'm not sure exactly which one(s).



This page took 0 seconds to execute

Last modified: Thu, 15 Apr 21 08:11:13 -0700

Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.