1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/stopwatch.h
3 // Purpose: wxStopWatch and global time-related functions
4 // Author: Julian Smart (wxTimer), Sylvain Bougnoux (wxStopWatch),
5 // Vadim Zeitlin (time functions, current wxStopWatch)
6 // Created: 26.06.03 (extracted from wx/timer.h)
7 // Copyright: (c) 1998-2003 Julian Smart, Sylvain Bougnoux
8 // (c) 2011 Vadim Zeitlin
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #ifndef _WX_STOPWATCH_H_
13 #define _WX_STOPWATCH_H_
16 #include "wx/longlong.h"
18 // Time-related functions are also available via this header for compatibility
19 // but you should include wx/time.h directly if you need only them and not
20 // wxStopWatch itself.
23 // ----------------------------------------------------------------------------
24 // wxStopWatch: measure time intervals with up to 1ms resolution
25 // ----------------------------------------------------------------------------
29 class WXDLLIMPEXP_BASE wxStopWatch
32 // ctor starts the stop watch
33 wxStopWatch() { m_pauseCount
= 0; Start(); }
35 // Start the stop watch at the moment t0 expressed in milliseconds (i.e.
36 // calling Time() immediately afterwards returns t0). This can be used to
37 // restart an existing stopwatch.
38 void Start(long t0
= 0);
40 // pause the stop watch
43 if ( m_pauseCount
++ == 0 )
44 m_elapsedBeforePause
= GetCurrentClockValue() - m_t0
;
50 wxASSERT_MSG( m_pauseCount
> 0,
51 wxT("Resuming stop watch which is not paused") );
53 if ( --m_pauseCount
== 0 )
56 m_t0
-= m_elapsedBeforePause
;
60 // Get elapsed time since the last Start() in microseconds.
61 wxLongLong
TimeInMicro() const;
63 // get elapsed time since the last Start() in milliseconds
64 long Time() const { return (TimeInMicro()/1000).ToLong(); }
67 // Really starts the stop watch. The initial time is set to current clock
71 // Returns the current clock value in its native units.
72 wxLongLong
GetCurrentClockValue() const;
74 // Return the frequency of the clock used in its ticks per second.
75 wxLongLong
GetClockFreq() const;
78 // The clock value when the stop watch was last started. Its units vary
79 // depending on the platform.
82 // The elapsed time as of last Pause() call (only valid if m_pauseCount >
83 // 0) in the same units as m_t0.
84 wxLongLong m_elapsedBeforePause
;
86 // if > 0, the stop watch is paused, otherwise it is running
90 #endif // wxUSE_STOPWATCH
92 #if wxUSE_LONGLONG && WXWIN_COMPATIBILITY_2_6
94 // Starts a global timer
95 // -- DEPRECATED: use wxStopWatch instead
96 wxDEPRECATED( void WXDLLIMPEXP_BASE
wxStartTimer() );
98 // Gets elapsed milliseconds since last wxStartTimer or wxGetElapsedTime
99 // -- DEPRECATED: use wxStopWatch instead
100 wxDEPRECATED( long WXDLLIMPEXP_BASE
wxGetElapsedTime(bool resetTimer
= true) );
102 #endif // wxUSE_LONGLONG && WXWIN_COMPATIBILITY_2_6
104 #endif // _WX_STOPWATCH_H_