Author: Hristo
Date: 22:01:03 10/28/03
Go up one level in this thread
On October 28, 2003 at 18:16:23, macaroni wrote:
>I have been using the clock() c++ function in my timeout function. However, I
>have noticed that occasionally my program doesn't think for nearly as long as it
>should, and moves even before it has a legal ply 1 move to play. I have narrowed
>it down to the timeout function, but can't understand why it doesn't work...does
>the clock() function ever 'turnover' and go back to 0, if so, how frequently?
>could this be the cause of the problem, and if so, what can I do about it?
>cheers
clock() rolls around.
The return value is 32 bit integer and the frequency with which this integer is
incremented is quite high. TICKS_PER_SECOND? rollAroundInSeconds =
(2^32)/TICKS_PER_SECOND;
Here is what I have been using; unix.
#import <sys/time.h>
class Chronometer{
public:
Chronometer();
~Chronometer();
void start();
void stop();
double elapsed();
private:
struct timeval m_startTime;
struct timeval m_stopTime;
};
Chronometer::Chronometer(){
m_startTime.tv_sec = 0;
m_startTime.tv_usec = 0;
m_stopTime.tv_sec = 0;
m_stopTime.tv_usec = 0;
}
Chronometer::~Chronometer()
{}
//
void Chronometer::start(){
gettimeofday(&m_startTime, NULL);
}
void Chronometer::stop(){
gettimeofday(&m_stopTime, NULL);
}
double Chronometer::elapsed(){
double ellapsed = 0.0;
if (m_startTime.tv_sec <= m_stopTime.tv_sec &&
m_startTime.tv_usec < m_stopTime.tv_sec)
{
ellapsed = m_stopTime.tv_usec - m_startTime.tv_usec;
ellapsed /= 1000000.0;
ellapsed += m_stopTime.tv_sec - m_startTime.tv_sec;
}
return ellapsed;
}
Cheers,
Hristo
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.