This class encapsulates a system dependent time value (Ticks) and provides some basic interface for measuring time spans, including multiple samples and their average.
The interface does provide nanosecond versions the methods. However, the internal resolution of the used timer is system dependent and might be lower than nanoseconds.
Public Methods | |
TickWatch () | |
TickWatch (TickWatch copy) | |
Ticks | getAverage () |
Ticks | getAverage (Ticks result) |
Ticks | getCumulated () |
int | getSampleCnt () |
Ticks | getStartTime () |
void | reset () |
Ticks | sample () |
void | setStartTime (Ticks t) |
void | start () |
Protected Fields | |
int | cntSamples |
Ticks | sum = new Ticks( 0L ) |
Ticks | tempTicks |
Ticks | ticks = new Ticks( 0L ) |
Ticks getAverage | ( | ) |
Returns the average time of all samples since this instance was created or reset. If no measurement was performed, the result value will be set to 0 ticks.
Note: Attention: The object returned is a temporary object, deemed to be reused by other interface methods of this instance. Therefore, it must be used only until subsequent method invocations on this instance are performed (hence, also not thread safe!) Use getAverage(Ticks result) to provide a dedicated external result instance.
Returns the average time of all samples since this instance was created or reset. If no measurement was performed, the result value will be set to 0 ticks.
result | An object to store the result in. If not provided (null), a result object is created. |
Ticks getCumulated | ( | ) |
Returns the cumulated length of all samples taken since this instance was created or cleared. Note: the object returned will be reused in subsequent calls to this method. Hence, previously returned values will be overwritten!
int getSampleCnt | ( | ) |
Ticks getStartTime | ( | ) |
void reset | ( | ) |
Sets the internal value to current system time and clears any existing sum and quantity of samples.
Ticks sample | ( | ) |
Returns the time span between the current system time and the internal reference value. In addition this value is added to the sum of sample times and the sample counter is increased by one. Lastly the internal reference value is set to now. Therefore, a subsequent call to this function would measure the time span from this call to this subsequent call (if the internal reference value was not set differently meanwhile). Other interface methods dealing with samples are getSampleCnt, getCumulated and getAverage.
void setStartTime | ( | Ticks | t | ) |
Sets the internal time value. This affects both, the reference value for the calculation of this TickWatchs age in subsequent calls, as well as subsequent sample time spans.
t | The value. |
void start | ( | ) |
Sets the internal value to current system time. This affects both, the reference value for the calculation of this TickWatchs age in subsequent calls, as well as subsequent sample time spans.
|
protected |
The number of samples performed.