|
Low-cost, high-resolution timer datatype. More...
#include <stopwatch.h>
Public Member Functions | |
void | Start () |
Record the current time for use by the next Stop() call. | |
void | Stop () |
Increases the accumulated time stored in the TfStopwatch . | |
void | Reset () |
Resets the accumulated time and the sample count to zero. | |
void | AddFrom (const TfStopwatch &t) |
Adds the accumulated time and sample count from t into the TfStopwatch . | |
int64_t | GetNanoseconds () const |
Return the accumulated time in nanoseconds. | |
int64_t | GetMicroseconds () const |
Return the accumulated time in microseconds. | |
int64_t | GetMilliseconds () const |
Return the accumulated time in milliseconds. | |
size_t | GetSampleCount () const |
Return the current sample count. | |
double | GetSeconds () const |
Return the accumulated time in seconds as a double . | |
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 38 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 80 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 98 of file stopwatch.h.
|
inline |
Return the accumulated time in milliseconds.
Definition at line 103 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 90 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 112 of file stopwatch.h.
|
inline |
Return the accumulated time in seconds as a double
.
Definition at line 117 of file stopwatch.h.
|
inline |
Resets the accumulated time and the sample count to zero.
Definition at line 68 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 48 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 62 of file stopwatch.h.