Wanzyee Studio
TimeRecorder

Measure the elapsed time sections and provide better log text. More...

Public Member Functions

 TimeRecorder (string name=null, bool start=true)
 Create a new recorder and optional to start immediately. More...
 
override string ToString ()
 Return the current state, including all recorded sections. More...
 
void Start ()
 Start or resume measuring. More...
 
void Stop (string section=null, bool log=false)
 Stop measuring, optional to record if the section name set. More...
 
void Record (string section="")
 Record the current elapsed time, optional to append the section name to the default index. More...
 
void Reset ()
 Stop and reset all records. More...
 

Static Public Member Functions

static TimeRecorder Run (Action< int > action, string name=null, int count=10000, bool log=true)
 Run the action in the specified count of the times, then stop and log the elapsed time. More...
 

Public Attributes

readonly string name
 The name. More...
 
bool running => _watch.IsRunning
 Determine if the timer is currently running. More...
 
long elapsed => _watch.ElapsedMilliseconds
 Get the total elapsed time in milliseconds. More...
 

Detailed Description

Measure the elapsed time sections and provide better log text.

Constructor & Destructor Documentation

TimeRecorder ( string  name = null,
bool  start = true 
)

Create a new recorder and optional to start immediately.

Returns
The instance.
Parameters
nameName.
startStart.

Member Function Documentation

static TimeRecorder Run ( Action< int >  action,
string  name = null,
int  count = 10000,
bool  log = true 
)
static

Run the action in the specified count of the times, then stop and log the elapsed time.

Parameters
actionThe action, the parameter is the current count started from 0.
nameThe name.
countThe count.
logIf to log when done.
Returns
The time recorder.
override string ToString ( )

Return the current state, including all recorded sections.

Include this's name, running state, and the current elapsed time at the first row. Then each row of section, i.e., recording time, duration, and the name at the end for better format.

Returns
A string represents this.
void Start ( )

Start or resume measuring.

void Stop ( string  section = null,
bool  log = false 
)

Stop measuring, optional to record if the section name set.

Parameters
sectionSection name.
logIf to log when done.
void Record ( string  section = "")

Record the current elapsed time, optional to append the section name to the default index.

Parameters
sectionSection name.
void Reset ( )

Stop and reset all records.

Member Data Documentation

readonly string name

The name.

bool running => _watch.IsRunning

Determine if the timer is currently running.

long elapsed => _watch.ElapsedMilliseconds

Get the total elapsed time in milliseconds.