Bonjour,
Comment chronom�trer le temps de fonctions en ms.
J'ai utilis� GetTickCount, mais il ne semble pas assez pr�cis (r�solution minimale = 10 ms).
Cordialement,
Christophe,
Bonjour,
Comment chronom�trer le temps de fonctions en ms.
J'ai utilis� GetTickCount, mais il ne semble pas assez pr�cis (r�solution minimale = 10 ms).
Cordialement,
Christophe,
Bonjour,
Tu peux utiliser les timer multimedia. Ils sont plus pr�cis, mais rien ne te garantit que tu auras une pr�cision � la ms.
Ressources propos�es par 3DArchi - Les fonctions virtuelles en C++ - Cours et tutoriels C++ - FAQ C++ - Forum C++.
Si tu veux une meilleure pr�cision, tu peux utiliser le Compteur de Performance.
On le consulte avec QueryPerformanceCounter() et on connait sa fr�quence avec QueryPerformanceFrequency().
SVP, pas de questions techniques par MP. Surtout si je ne vous ai jamais parl� avant.
"Aw, come on, who would be so stupid as to insert a cast to make an error go away without actually fixing the error?"
Apparently everyone. -- Raymond Chen.
Traduction obligatoire: "Oh, voyons, qui serait assez stupide pour mettre un cast pour faire disparaitre un message d'erreur sans vraiment corriger l'erreur?" - Apparemment, tout le monde. -- Raymond Chen.
Regarde ici : http://www.codeproject.com/KB/system/timers_intro.aspx
J'ai utilis� les Queue timers et �a marche plut�t bien.
Salut,
Voici un peu de code
Une classe int�ressante!!!
Voici un exemple d'utilisation
Code : S�lectionner tout - Visualiser dans une fen�tre � part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90 namespace MCN { class CMcnPerformanceTime { public: CMcnPerformanceTime(bool bAuto = true) { m_bStarted = false; if(bAuto) Start(); } virtual ~CMcnPerformanceTime() { } static CString FormatMessage() { LPVOID lpMsgBuf; ::FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, ::GetLastError(), 0, (LPTSTR) &lpMsgBuf, 0, NULL); CString strLastError = (LPCSTR)lpMsgBuf; ::LocalFree( lpMsgBuf ); return strLastError; } bool Start() { m_bStarted = false; if( ::QueryPerformanceFrequency(&m_nFrequency) == FALSE) { m_strLastError = FormatMessage(); return false; } if( ::QueryPerformanceCounter(&m_nBeginTime) == FALSE) { m_strLastError = FormatMessage(); return false; } m_strLastError.Empty(); m_bStarted = true; return true; } long double Stop() { if(m_bStarted == false) { m_strLastError = "Time counter not started\n"; return 0; } m_bStarted = false; if ( ::QueryPerformanceCounter(&m_nEndTime) == FALSE) { m_strLastError = FormatMessage(); return 0; } m_strLastError.Empty(); long double nElapseTime = (long double) ( m_nEndTime.QuadPart - m_nBeginTime.QuadPart ); nElapseTime /= m_nFrequency.QuadPart; nElapseTime *= 1000; return nElapseTime; // nanosecondes } CStringA GetLastError() const { return m_strLastError; } private: LARGE_INTEGER m_nFrequency; LARGE_INTEGER m_nBeginTime; LARGE_INTEGER m_nEndTime; CStringA m_strLastError; bool m_bStarted; }; // class CMcnPerformanceTime } // namespace MCN
Code : S�lectionner tout - Visualiser dans une fen�tre � part
1
2
3
4
5
6
7
8
9
10
11
12
13 void MyFunction() { MCN::CMcnPerformanceTime timer(false); timer.Start(); // start the timer // work, work, work... long double dElapse = timer.Stop(); // stop the timer // bon combien dans dElapse in nanoseconde??? }![]()
�a n'est pas la premi�re fois que je vois cette absurdit�:
Pourquoi passer par un LPVOID qu'on caste (mal) ?static CString FormatMessage()
{
LPVOID lpMsgBuf;
::FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS, NULL,
::GetLastError(), 0, (LPTSTR) &lpMsgBuf, 0, NULL);
CString strLastError = (LPCSTR)lpMsgBuf;
::LocalFree( lpMsgBuf );
return strLastError;
}
Code C++ : S�lectionner tout - Visualiser dans une fen�tre � part
1
2
3
4
5
6
7
8
9
10
11
12 static CString FormatMessage() { LPTSTR lpMsgBuf; ::FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, ::GetLastError(), 0, reinterpret_cast<LPTSTR>(&lpMsgBuf), 0, NULL); CString strLastError = lpMsgBuf; ::LocalFree( lpMsgBuf ); return strLastError; }
SVP, pas de questions techniques par MP. Surtout si je ne vous ai jamais parl� avant.
"Aw, come on, who would be so stupid as to insert a cast to make an error go away without actually fixing the error?"
Apparently everyone. -- Raymond Chen.
Traduction obligatoire: "Oh, voyons, qui serait assez stupide pour mettre un cast pour faire disparaitre un message d'erreur sans vraiment corriger l'erreur?" - Apparemment, tout le monde. -- Raymond Chen.
Partager