Develop and Download Open Source Software

Browse Subversion Repository

Annotation of /WcsAPI/Stopwatch.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 11 - (hide annotations) (download) (as text)
Wed Feb 10 18:21:00 2010 UTC (14 years, 2 months ago) by sho1get
File MIME type: text/x-chdr
File size: 1490 byte(s)


1 sho1get 11 #pragma once
2    
3     //////////////////////////////////////////////////////////////////////////
4    
5     class CStopwatch
6     {
7     private:
8     LARGE_INTEGER m_liPerfFreq;
9     LARGE_INTEGER m_liPerfStart;
10    
11     public:
12     CStopwatch()
13     {
14     QueryPerformanceFrequency(&m_liPerfFreq);
15     }
16    
17     virtual ~CStopwatch() {}
18    
19     void Start()
20     {
21     QueryPerformanceCounter(&m_liPerfStart);
22     }
23    
24     INT64 NowByMillisecond() const
25     {
26     LARGE_INTEGER liPerfNow;
27     QueryPerformanceCounter(&liPerfNow);
28     return (INT64)(((liPerfNow.QuadPart - m_liPerfStart.QuadPart) * 1000)
29     / m_liPerfFreq.QuadPart);
30     }
31    
32     INT64 NowByMicrosecond() const
33     {
34     LARGE_INTEGER liPerfNow;
35     QueryPerformanceCounter(&liPerfNow);
36     return (INT64)(((liPerfNow.QuadPart - m_liPerfStart.QuadPart) * 1000000)
37     / m_liPerfFreq.QuadPart);
38     }
39    
40     double NowBySecond() const
41     {
42     return static_cast<double>(NowByMicrosecond() / 1000000);
43     }
44    
45     void GetHMS(CString &cs)
46     {
47     LARGE_INTEGER liPerfNow;
48     UINT uHour, uMinute, uSecond;
49     INT64 liNowTime;
50    
51     QueryPerformanceCounter(&liPerfNow);
52     liNowTime = (INT64)((liPerfNow.QuadPart - m_liPerfStart.QuadPart)
53     / m_liPerfFreq.QuadPart);
54    
55     uHour = static_cast<UINT>(liNowTime / 3600);
56     uMinute = static_cast<UINT>((liNowTime - uHour * 3600) / 60);
57     uSecond = static_cast<UINT>(liNowTime - (uHour * 3600 + uMinute * 60));
58    
59     cs.Format(_T("%02d:%02d:%02d"), uHour, uMinute, uSecond);
60     }
61     };
62    
63     //////////////////////////////////////////////////////////////////////////

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26