timestat: 增加 CYCLE_STAT 宏但仅为示例用故不启用

This commit is contained in:
Calcitem 2019-11-10 12:36:31 +08:00
parent 5a085560f3
commit a3f9059528
5 changed files with 48 additions and 0 deletions

View File

@ -46,6 +46,7 @@
//#define HARD_LEVEL_DEPTH
//#define TIME_STAT
//#define CYCLE_STAT
//#define MIN_MAX_ONLY

View File

@ -415,6 +415,9 @@ void AIAlgorithm::sortMoves(Node *node)
#ifdef TIME_STAT
auto timeStart = now();
#endif
#ifdef CYCLE_STAT
auto cycleStart = stopwatch::rdtscp_clock::now();
#endif
NODE_PTR_SORT_FUN(sqrt_sort_sort_ins)(node->children, node->childrenSize);
@ -422,6 +425,10 @@ void AIAlgorithm::sortMoves(Node *node)
auto timeEnd = now();
sortTime += (timeEnd - timeStart);
#endif
#ifdef CYCLE_STAT
auto cycleEnd = stopwatch::rdtscp_clock::now();
sortCycle += (cycleEnd - cycleStart);
#endif
#ifdef DEBUG_SORT
if (tempGame.position.sideToMove == PLAYER_BLACK) {
@ -516,6 +523,10 @@ int AIAlgorithm::search(depth_t depth)
auto timeStart = chrono::steady_clock::now();
chrono::steady_clock::time_point timeEnd;
#endif
#ifdef CYCLE_STAT
auto cycleStart = stopwatch::rdtscp_clock::now();
chrono::steady_clock::time_point cycleEnd;
#endif
#ifdef THREEFOLD_REPETITION
static int nRepetition = 0;

View File

@ -42,6 +42,9 @@
#include "types.h"
#include "memmgr.h"
#include "misc.h"
#ifdef CYCLE_STAT
#include "stopwatch.h"
#endif
using namespace std;
using namespace CTSL;
@ -102,6 +105,12 @@ public:
// 排序算法耗时 (ms)
TimePoint sortTime { 0 };
#endif
#ifdef CYCLE_STAT
// 排序算法耗费时间周期 (TODO: 计算单次或平均)
stopwatch::rdtscp_clock::time_point sortCycle;
stopwatch::timer::duration sortCycle { 0 };
stopwatch::timer::period sortCycle;
#endif
public:
AIAlgorithm();

View File

@ -57,6 +57,7 @@ GameController::GameController(
gameStartTime(0),
gameEndTime(0),
gameDurationTime(0),
gameDurationCycle(0),
hasSound(true),
timeID(0),
ruleIndex(-1),
@ -148,6 +149,7 @@ void GameController::gameStart()
}
gameStartTime = now();
gameStartCycle = stopwatch::rdtscp_clock::now();
}
void GameController::gameReset()
@ -956,6 +958,8 @@ bool GameController::command(const QString &cmd, bool update /* = true */)
gameEndTime = now();
gameDurationTime = gameEndTime - gameStartTime;
gameEndCycle = stopwatch::rdtscp_clock::now();
loggerDebug("Game Duration Time: %dms\n", gameDurationTime);
#ifdef TIME_STAT
@ -964,6 +968,19 @@ bool GameController::command(const QString &cmd, bool update /* = true */)
(aiThread[BLACK]->ai.sortTime + aiThread[WHITE]->ai.sortTime));
aiThread[BLACK]->ai.sortTime = aiThread[WHITE]->ai.sortTime = 0;
#endif // TIME_STAT
#ifdef CYCLE_STAT
loggerDebug("Sort Cycle: %ld + %ld = %ld\n",
aiThread[BLACK]->ai.sortCycle, aiThread[WHITE]->ai.sortCycle,
(aiThread[BLACK]->ai.sortCycle + aiThread[WHITE]->ai.sortCycle));
aiThread[BLACK]->ai.sortCycle = aiThread[WHITE]->ai.sortCycle = 0;
#endif // CYCLE_STAT
#if 0
gameDurationCycle = gameEndCycle - gameStartCycle;
loggerDebug("Game Start Cycle: %u\n", gameStartCycle);
loggerDebug("Game End Cycle: %u\n", gameEndCycle);
loggerDebug("Game Duration Cycle: %u\n", gameDurationCycle);
#endif
#ifdef TRANSPOSITION_TABLE_DEBUG
size_t hashProbeCount_1 = aiThread[BLACK]->ai.hashHitCount + aiThread[BLACK]->ai.hashMissCount;

View File

@ -42,6 +42,7 @@
#include "thread.h"
#include "server.h"
#include "client.h"
#include "stopwatch.h"
using namespace std;
@ -251,6 +252,15 @@ private:
// 游戏持续时间
TimePoint gameDurationTime;
// 游戏开始周期
stopwatch::rdtscp_clock::time_point gameStartCycle;
// 游戏结束周期
stopwatch::rdtscp_clock::time_point gameEndCycle;
// 游戏持续周期
stopwatch::rdtscp_clock::duration gameDurationCycle;
// 是否有落子音效
bool hasSound;