tango.time.StopWatch

License:

BSD style: see license.txt

Version:

Feb 2007: Initial release

Author:

Kris
struct StopWatch [public]
Timer for measuring small intervals, such as the duration of a subroutine or other reasonably small period.
1
2
3
4
5
6
7
8
StopWatch elapsed;

elapsed.start;

// do something
// ...

double i = elapsed.stop;
The measured interval is in units of seconds, using floating- point to represent fractions. This approach is more flexible than integer arithmetic since it migrates trivially to more capable timer hardware (there no implicit granularity to the measurable intervals, except the limits of fp representation)

StopWatch is accurate to the extent of what the underlying OS supports. On linux systems, this accuracy is typically 1 us at best. Win32 is generally more precise.

There is some minor overhead in using StopWatch, so take that into account
void start()
Start the timer
double stop()
Stop the timer and return elapsed duration since start()
ulong microsec() [@property]
Return elapsed time since the last start() as microseconds
static this() [shared]
Setup timing information for later use