Knight's Tour Generator
Tourneys and the Fast Generation and Obfuscation of Closed Knight's Tours
Public Member Functions | Private Member Functions | Private Attributes | List of all members
CTimer Class Reference

Timer for elapsed time and CPU time. More...

#include <Timer.h>

Public Member Functions

const char * GetStartDateAndTime ()
 Get start time and date. More...
 
const char * GetCurrentDateAndTime ()
 Get current time and date. More...
 
void Start ()
 Start timing. More...
 
float GetElapsedTime ()
 Get elapsed time in seconds. More...
 
float GetCPUTime ()
 Get CPU time in seconds. More...
 
void Finish ()
 Print CPU and elapsed time. More...
 

Private Member Functions

const char * GetDateAndTime (const systime_point p)
 Get time and date. More...
 
UINT CPUTime ()
 Platform independent CPU time. More...
 

Private Attributes

systime_point m_tpElapsedTimeStart
 Clock time.
 
float m_fCPUTimeStart
 CPU time in seconds.
 
std::string m_strTimeAndDate
 Container for time and date string.
 

Detailed Description

The timer is charged with everything that is time-related, in particular, elapsed time, CPU time, and clock time. The member functions return time intervals measured from the time Start() is called to the current time. The CPU time reported is the total summed over all threads. Uses std::chrono to do the heavy lifting.

Definition at line 43 of file Timer.h.

Member Function Documentation

◆ CPUTime()

UINT CTimer::CPUTime ( )
private

Get CPU time for this process in seconds. It's annoying that std::chron has no cross-platform support for this.

Returns
User CPU time in seconds.

Definition at line 117 of file Timer.cpp.

◆ Finish()

void CTimer::Finish ( )

Print the elapsed and CPU time in seconds since the start of the search to stdout.

Definition at line 83 of file Timer.cpp.

◆ GetCPUTime()

float CTimer::GetCPUTime ( )

Get the amount of CPU time used since the timer was started.

Returns
CPU time in seconds.

Definition at line 76 of file Timer.cpp.

◆ GetCurrentDateAndTime()

const char * CTimer::GetCurrentDateAndTime ( )

Get the current date and time as a null-terminated string. Uses GetDateAndTime() to do the heavy lifting.

Returns
Pointer to first character in a null-terminated string.

Definition at line 61 of file Timer.cpp.

◆ GetDateAndTime()

const char * CTimer::GetDateAndTime ( const systime_point  p)
private

Get time and date string into m_strTimeAndDate from a systime_point and return it as a null-terminated string. We're using a member variable to store an std::string so that its c_str() pointer is persistent.

Parameters
pAn instance of systime_point.
Returns
The corresponding time and date string.

Definition at line 43 of file Timer.cpp.

◆ GetElapsedTime()

float CTimer::GetElapsedTime ( )

Get the amount of time elapsed since the timer was started.

Returns
Elapsed time in seconds.

Definition at line 68 of file Timer.cpp.

◆ GetStartDateAndTime()

const char * CTimer::GetStartDateAndTime ( )

Get the start date and time as a null-terminated string. Uses GetDateAndTime() to do the heavy lifting.

Returns
Pointer to first character in a null-terminated string.

Definition at line 53 of file Timer.cpp.

◆ Start()

void CTimer::Start ( )

Start timing by saving the current elapsed and CPU times.

Definition at line 32 of file Timer.cpp.