1 // Duration.h: interface for the Duration class.
3 //////////////////////////////////////////////////////////////////////
5 #if !defined(AFX_DURATION_H__95A8A4BA_3CFB_4ABC_8C48_495328EA1336__INCLUDED_)
6 #define AFX_DURATION_H__95A8A4BA_3CFB_4ABC_8C48_495328EA1336__INCLUDED_
10 #endif // _MSC_VER > 1000
17 #define TIMEVAL struct timeval
18 #define TIMEVAL struct timeval
24 #define GET_TIME(T) gettimeofday(&T,NULL)
25 #define ELAPSED_TIME_SEC(B, A) \
26 static_cast<double>((A.tv_sec - B.tv_sec) + (1.E-6 * (A.tv_usec - B.tv_usec))) // B = start; A = end #endif
33 virtual ~Duration() {};
37 double GetDuration(void) const;
38 double GetDurationInMs(void) const;
43 LARGE_INTEGER m_liStart
;
44 LARGE_INTEGER m_liStop
;
46 LONGLONG m_llFrequency
;
47 LONGLONG m_llCorrection
;
51 // LONGLONG m_llCorrection;
56 inline Duration::Duration(void)
59 LARGE_INTEGER liFrequency
;
61 QueryPerformanceFrequency(&liFrequency
);
62 m_llFrequency
= liFrequency
.QuadPart
;
68 m_llCorrection
= m_liStop
.QuadPart
-m_liStart
.QuadPart
;
74 // m_llCorrection = GetDuration();
78 inline void Duration::Start(void)
82 // Ensure we will not be interrupted by any other thread for a while
84 QueryPerformanceCounter(&m_liStart
);
92 inline void Duration::Stop(void)
95 QueryPerformanceCounter(&m_liStop
);
102 inline double Duration::GetDuration(void) const
105 return (double)(m_liStop
.QuadPart
-m_liStart
.QuadPart
-m_llCorrection
)*1000000.0 / m_llFrequency
;
107 return ELAPSED_TIME_SEC(m_liStart
, m_liStop
);
111 inline double Duration::GetDurationInMs(void) const
114 return (double)(m_liStop
.QuadPart
-m_liStart
.QuadPart
-m_llCorrection
)*1000000.0 / m_llFrequency
/1000.0;
116 return ELAPSED_TIME_SEC(m_liStart
, m_liStop
)*1000.0; ///not sure !!!
121 #endif // !defined(AFX_DURATION_H__95A8A4BA_3CFB_4ABC_8C48_495328EA1336__INCLUDED_)