HDK
|
#include <stopwatch.h>
Public Member Functions | |
void | Start () |
void | Stop () |
void | Reset () |
Resets the accumulated time and the sample count to zero. More... | |
void | AddFrom (const TfStopwatch &t) |
int64_t | GetNanoseconds () const |
int64_t | GetMicroseconds () const |
int64_t | GetMilliseconds () const |
Return the accumulated time in milliseconds. More... | |
size_t | GetSampleCount () const |
double | GetSeconds () const |
Return the accumulated time in seconds as a double . More... | |
Low-cost, high-resolution timer datatype.
A TfStopwatch
can be used to perform very precise timings at runtime, even in very tight loops. The cost of "starting" or "stopping" a TfStopwatch
is very small: approximately 40 nanoseconds on a 900 Mhz Pentium III Linux box, 300 nanoseconds on a 400 Mhz Sun, and 200 nanoseconds on a 250 Mhz SGI.
Note that this class is not thread-safe: if you need to take timings in a multi-threaded region of a process, let each thread have its own TfStopwatch
and then combine results using the AddFrom()
member function.
Definition at line 55 of file stopwatch.h.
|
inline |
Adds the accumulated time and sample count from t
into the TfStopwatch
.
If you have several timers taking measurements, and you wish to combine them together, you can add one timer's results into another; for example, t2.AddFrom(t1)
will add t1
's time and sample count into t2
.
Definition at line 97 of file stopwatch.h.
|
inline |
Return the accumulated time in microseconds
Note that 45 minutes will overflow a 32-bit counter, so take care to save the result in an int64_t
, and not a regular int
or long
.
Definition at line 115 of file stopwatch.h.
|
inline |
Return the accumulated time in milliseconds.
Definition at line 120 of file stopwatch.h.
|
inline |
Return the accumulated time in nanoseconds.
Note that this number can easily overflow a 32-bit counter, so take care to save the result in an int64_t
, and not a regular int
or long
.
Definition at line 107 of file stopwatch.h.
|
inline |
Return the current sample count.
The sample count, which is simply the number of calls to Stop()
since creation or a call to Reset()
, is useful for computing average running times of a repeated task.
Definition at line 129 of file stopwatch.h.
|
inline |
Return the accumulated time in seconds as a double
.
Definition at line 134 of file stopwatch.h.
|
inline |
Resets the accumulated time and the sample count to zero.
Definition at line 85 of file stopwatch.h.
|
inline |
Record the current time for use by the next Stop()
call.
The Start()
function records the current time. A subsequent call to Start()
before a call to Stop()
simply records a later current time, but does not change the accumulated time of the TfStopwatch
.
Definition at line 65 of file stopwatch.h.
|
inline |
Increases the accumulated time stored in the TfStopwatch
.
The Stop()
function increases the accumulated time by the duration between the current time and the last time recorded by a Start()
call. A subsequent call to Stop()
before another call to Start()
will therefore double-count time and throw off the results.
A TfStopwatch
also counts the number of samples it has taken. The "sample count" is simply the number of times that Stop()
has been called.
Definition at line 79 of file stopwatch.h.