summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
5900ab7)
We just need the milliseconds of current system
time for our needs. This allows to simplify the
API.
No functional change.
int64_t nodes = 0;
Search::StateStackPtr st;
int64_t nodes = 0;
Search::StateStackPtr st;
- Time time = Time::now();
+ Time::point t = Time::now();
for (size_t i = 0; i < fens.size(); i++)
{
for (size_t i = 0; i < fens.size(); i++)
{
- int e = time.elapsed() + 1; // Assure positive to avoid a 'divide by zero'
+ int e = Time::now() - t + 1; // Assure positive to avoid a 'divide by zero'
cerr << "\n==========================="
<< "\nTotal time (ms) : " << e
cerr << "\n==========================="
<< "\nTotal time (ms) : " << e
- for (int i = Time::now().msec() % 10000; i > 0; i--)
+ for (int i = Time::now() % 10000; i > 0; i--)
RKiss.rand<unsigned>(); // Make random number generation less deterministic
}
RKiss.rand<unsigned>(); // Make random number generation less deterministic
}
+/// Convert system time to milliseconds. That's all we need.
+
+Time::point Time::now() {
+ sys_time_t t; system_time(&t); return time_to_msec(t);
+}
+
+
/// Debug functions used mainly to collect run-time statistics
static uint64_t hits[2], means[2];
/// Debug functions used mainly to collect run-time statistics
static uint64_t hits[2], means[2];
int tm = msec;
#else
timespec ts, *tm = &ts;
int tm = msec;
#else
timespec ts, *tm = &ts;
- uint64_t ms = Time::now().msec() + msec;
+ uint64_t ms = Time::now() + msec;
ts.tv_sec = ms / 1000;
ts.tv_nsec = (ms % 1000) * 1000000LL;
ts.tv_sec = ms / 1000;
ts.tv_nsec = (ms % 1000) * 1000000LL;
-struct Time {
- int64_t msec() const { return time_to_msec(t); }
- int elapsed() const { return int(now().msec() - msec()); }
-
- static Time now() { Time t; system_time(&t.t); return t; }
-
-private:
- sys_time_t t;
-};
+namespace Time {
+ typedef int64_t point;
+ point now();
+}
template<class Entry, int Size>
template<class Entry, int Size>
LimitsType Limits;
std::vector<RootMove> RootMoves;
Position RootPosition;
LimitsType Limits;
std::vector<RootMove> RootMoves;
Position RootPosition;
+ Time::point SearchTime;
StateStackPtr SetupStates;
}
StateStackPtr SetupStates;
}
if (Options["Use Search Log"])
{
if (Options["Use Search Log"])
{
- int e = SearchTime.elapsed();
+ int e = Time::now() - SearchTime;
Log log(Options["Search Log Filename"]);
log << "Nodes: " << pos.nodes_searched()
Log log(Options["Search Log Filename"]);
log << "Nodes: " << pos.nodes_searched()
// Send full PV info to GUI if we are going to leave the loop or
// if we have a fail high/low and we are deep in the search.
// Send full PV info to GUI if we are going to leave the loop or
// if we have a fail high/low and we are deep in the search.
- if ((bestValue > alpha && bestValue < beta) || SearchTime.elapsed() > 2000)
+ if ((bestValue > alpha && bestValue < beta) || Time::now() - SearchTime > 2000)
sync_cout << uci_pv(pos, depth, alpha, beta) << sync_endl;
// In case of failing high/low increase aspiration window and
sync_cout << uci_pv(pos, depth, alpha, beta) << sync_endl;
// In case of failing high/low increase aspiration window and
if (!Signals.stop && Options["Use Search Log"])
{
Log log(Options["Search Log Filename"]);
if (!Signals.stop && Options["Use Search Log"])
{
Log log(Options["Search Log Filename"]);
- log << pretty_pv(pos, depth, bestValue, SearchTime.elapsed(), &RootMoves[0].pv[0])
+ log << pretty_pv(pos, depth, bestValue, Time::now() - SearchTime, &RootMoves[0].pv[0])
// Stop search if most of available time is already consumed. We
// probably don't have enough time to search the first move at the
// next iteration anyway.
// Stop search if most of available time is already consumed. We
// probably don't have enough time to search the first move at the
// next iteration anyway.
- if (SearchTime.elapsed() > (TimeMgr.available_time() * 62) / 100)
+ if (Time::now() - SearchTime > (TimeMgr.available_time() * 62) / 100)
stop = true;
// Stop search early if one move seems to be much better than others
if ( depth >= 12
&& !stop
&& ( (bestMoveNeverChanged && pos.captured_piece_type())
stop = true;
// Stop search early if one move seems to be much better than others
if ( depth >= 12
&& !stop
&& ( (bestMoveNeverChanged && pos.captured_piece_type())
- || SearchTime.elapsed() > (TimeMgr.available_time() * 40) / 100))
+ || Time::now() - SearchTime > (TimeMgr.available_time() * 40) / 100))
{
Value rBeta = bestValue - EasyMoveMargin;
(ss+1)->excludedMove = RootMoves[0].pv[0];
{
Value rBeta = bestValue - EasyMoveMargin;
(ss+1)->excludedMove = RootMoves[0].pv[0];
{
Signals.firstRootMove = (moveCount == 1);
{
Signals.firstRootMove = (moveCount == 1);
- if (thisThread == Threads.main_thread() && SearchTime.elapsed() > 2000)
+ if (thisThread == Threads.main_thread() && Time::now() - SearchTime > 2000)
sync_cout << "info depth " << depth / ONE_PLY
<< " currmove " << move_to_uci(move, Chess960)
<< " currmovenumber " << moveCount + PVIdx << sync_endl;
sync_cout << "info depth " << depth / ONE_PLY
<< " currmove " << move_to_uci(move, Chess960)
<< " currmovenumber " << moveCount + PVIdx << sync_endl;
static RKISS rk;
// PRNG sequence should be not deterministic
static RKISS rk;
// PRNG sequence should be not deterministic
- for (int i = Time::now().msec() % 50; i > 0; i--)
+ for (int i = Time::now() % 50; i > 0; i--)
rk.rand<unsigned>();
// RootMoves are already sorted by score in descending order
rk.rand<unsigned>();
// RootMoves are already sorted by score in descending order
string uci_pv(const Position& pos, int depth, Value alpha, Value beta) {
std::stringstream s;
string uci_pv(const Position& pos, int depth, Value alpha, Value beta) {
std::stringstream s;
- int t = SearchTime.elapsed();
+ int t = Time::now() - SearchTime;
int selDepth = 0;
for (size_t i = 0; i < Threads.size(); i++)
int selDepth = 0;
for (size_t i = 0; i < Threads.size(); i++)
- static Time lastInfoTime = Time::now();
+ static Time::point lastInfoTime = Time::now();
- if (lastInfoTime.elapsed() >= 1000)
+ if (Time::now() - lastInfoTime >= 1000)
{
lastInfoTime = Time::now();
dbg_print();
{
lastInfoTime = Time::now();
dbg_print();
if (Limits.ponder)
return;
if (Limits.ponder)
return;
- int e = SearchTime.elapsed();
+ int e = Time::now() - SearchTime;
bool stillAtFirstMove = Signals.firstRootMove
&& !Signals.failedLowAtRoot
&& e > TimeMgr.available_time();
bool stillAtFirstMove = Signals.firstRootMove
&& !Signals.failedLowAtRoot
&& e > TimeMgr.available_time();
extern LimitsType Limits;
extern std::vector<RootMove> RootMoves;
extern Position RootPosition;
extern LimitsType Limits;
extern std::vector<RootMove> RootMoves;
extern Position RootPosition;
+extern Time::point SearchTime;
extern StateStackPtr SetupStates;
extern void init();
extern StateStackPtr SetupStates;
extern void init();