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)
8 // Copyright: (c) 1998-2003 Julian Smart, Sylvain Bougnoux
9 // (c) 2011 Vadim Zeitlin
10 // Licence: wxWindows licence
11 /////////////////////////////////////////////////////////////////////////////
13 #ifndef _WX_STOPWATCH_H_
14 #define _WX_STOPWATCH_H_
17 #include "wx/longlong.h"
19 // Time-related functions are also available via this header for compatibility
20 // but you should include wx/time.h directly if you need only them and not
21 // wxStopWatch itself.
24 // ----------------------------------------------------------------------------
25 // wxStopWatch: measure time intervals with up to 1ms resolution
26 // ----------------------------------------------------------------------------
30 class WXDLLIMPEXP_BASE wxStopWatch
33 // ctor starts the stop watch
34 wxStopWatch() { m_pauseCount
= 0; Start(); }
36 // Start the stop watch at the moment t0 expressed in milliseconds (i.e.
37 // calling Time() immediately afterwards returns t0). This can be used to
38 // restart an existing stopwatch.
39 void Start(long t0
= 0);
41 // pause the stop watch
44 if ( m_pauseCount
++ == 0 )
45 m_elapsedBeforePause
= GetCurrentClockValue() - m_t0
;
51 wxASSERT_MSG( m_pauseCount
> 0,
52 wxT("Resuming stop watch which is not paused") );
54 if ( --m_pauseCount
== 0 )
57 m_t0
-= m_elapsedBeforePause
;
61 // Get elapsed time since the last Start() in microseconds.
62 wxLongLong
TimeInMicro() const;
64 // get elapsed time since the last Start() in milliseconds
65 long Time() const { return (TimeInMicro()/1000).ToLong(); }
68 // Really starts the stop watch. The initial time is set to current clock
72 // Returns the current clock value in its native units.
73 wxLongLong
GetCurrentClockValue() const;
75 // Return the frequency of the clock used in its ticks per second.
76 wxLongLong
GetClockFreq() const;
79 // The clock value when the stop watch was last started. Its units vary
80 // depending on the platform.
83 // The elapsed time as of last Pause() call (only valid if m_pauseCount >
84 // 0) in the same units as m_t0.
85 wxLongLong m_elapsedBeforePause
;
87 // if > 0, the stop watch is paused, otherwise it is running
91 #endif // wxUSE_STOPWATCH
93 #if wxUSE_LONGLONG && WXWIN_COMPATIBILITY_2_6
95 // Starts a global timer
96 // -- DEPRECATED: use wxStopWatch instead
97 wxDEPRECATED( void WXDLLIMPEXP_BASE
wxStartTimer() );
99 // Gets elapsed milliseconds since last wxStartTimer or wxGetElapsedTime
100 // -- DEPRECATED: use wxStopWatch instead
101 wxDEPRECATED( long WXDLLIMPEXP_BASE
wxGetElapsedTime(bool resetTimer
= true) );
103 #endif // wxUSE_LONGLONG && WXWIN_COMPATIBILITY_2_6
105 #endif // _WX_STOPWATCH_H_