2008-03-08 08:52:38 -05:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: stopwatch.h
|
2008-03-10 11:24:38 -04:00
|
|
|
// Purpose: interface of wxStopWatch
|
2008-03-08 08:52:38 -05:00
|
|
|
// Author: wxWidgets team
|
2010-07-13 09:29:13 -04:00
|
|
|
// Licence: wxWindows licence
|
2008-03-08 08:52:38 -05:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
/**
|
|
|
|
@class wxStopWatch
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-10-07 12:57:34 -04:00
|
|
|
The wxStopWatch class allow you to measure time intervals.
|
|
|
|
|
|
|
|
For example, you may use it to measure the time elapsed by some function:
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
@code
|
2008-10-07 12:57:34 -04:00
|
|
|
wxStopWatch sw;
|
2008-03-08 08:52:38 -05:00
|
|
|
CallLongRunningFunction();
|
|
|
|
wxLogMessage("The long running function took %ldms to execute",
|
|
|
|
sw.Time());
|
|
|
|
sw.Pause();
|
|
|
|
... stopwatch is stopped now ...
|
|
|
|
sw.Resume();
|
|
|
|
CallLongRunningFunction();
|
|
|
|
wxLogMessage("And calling it twice took $ldms in all", sw.Time());
|
|
|
|
@endcode
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2011-11-27 14:50:08 -05:00
|
|
|
Since wxWidgets 2.9.3 this class uses @c ::QueryPerformanceCounter()
|
|
|
|
function under MSW to measure the elapsed time. It provides higher
|
|
|
|
precision than the usual timer functions but can suffer from bugs in its
|
|
|
|
implementation in some Windows XP versions. If you encounter such problems,
|
|
|
|
installing a Microsoft hot fix from http://support.microsoft.com/?id=896256
|
|
|
|
could be necessary.
|
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
@library{wxbase}
|
|
|
|
@category{misc}
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-10 11:24:38 -04:00
|
|
|
@see wxTimer
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2008-03-08 09:43:31 -05:00
|
|
|
class wxStopWatch
|
2008-03-08 08:52:38 -05:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
Constructor. This starts the stop watch.
|
|
|
|
*/
|
|
|
|
wxStopWatch();
|
|
|
|
|
|
|
|
/**
|
2008-10-07 12:57:34 -04:00
|
|
|
Pauses the stop watch. Call Resume() to resume time measuring again.
|
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
If this method is called several times, @c Resume() must be called the same
|
2008-03-08 09:43:31 -05:00
|
|
|
number of times to really resume the stop watch. You may, however, call
|
2008-03-08 08:52:38 -05:00
|
|
|
Start() to resume it unconditionally.
|
|
|
|
*/
|
|
|
|
void Pause();
|
|
|
|
|
|
|
|
/**
|
2008-10-07 12:57:34 -04:00
|
|
|
Resumes the stop watch which had been paused with Pause().
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
|
|
|
void Resume();
|
|
|
|
|
|
|
|
/**
|
|
|
|
(Re)starts the stop watch with a given initial value.
|
2011-12-02 19:34:00 -05:00
|
|
|
|
|
|
|
The stopwatch will always be running after calling Start(), even if
|
|
|
|
Pause() had been called before and even if it had been called multiple
|
|
|
|
times.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
|
|
|
void Start(long milliseconds = 0);
|
|
|
|
|
|
|
|
/**
|
2008-10-07 12:57:34 -04:00
|
|
|
Returns the time in milliseconds since the start (or restart) or the last
|
|
|
|
call of Pause().
|
2011-11-27 14:50:12 -05:00
|
|
|
|
|
|
|
@see TimeInMicro()
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2008-03-09 12:24:26 -04:00
|
|
|
long Time() const;
|
2011-11-27 14:50:12 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
Returns elapsed time in microseconds.
|
|
|
|
|
|
|
|
This method is similar to Time() but returns the elapsed time in
|
|
|
|
microseconds and not milliseconds. Notice that not all platforms really
|
|
|
|
can measure times with this precision.
|
|
|
|
|
|
|
|
@since 2.9.3
|
|
|
|
*/
|
|
|
|
wxLongLong TimeInMicro() const;
|
2008-03-08 08:52:38 -05:00
|
|
|
};
|
|
|
|
|