QA: How can I measure time in milliseconds?
Vassili Philippov (vasja@spbteam.com), July 19, 2001.
Question
How can I measure time in milliseconds? It seems like CTime
supports only seconds.
Answer
Unfortunally there is no good solution for that. All functions that could
help are described as OEM depended. It means that on some devices they
could work wrong.
One of the most simple way to measure time that works on most devices
is GetTickCount function that returns number of milliseconds
that have elapsed since Windows CE was started.
Source code
Here is a sample code that measures time of some action
DWORD dwStartTime = GetTickCount();
//Here are some actions that we measure
DWORD dwFinishTime = GetTickCount();
CString str;
str.Format(_T("The action took %d milliseconds."), (int)(dwFinishTime-dwStartTime));
AfxMessageBox(str);
Related resources:
-
http://www.pocketpcdn.com/articles/ctimetostring.html
QA: How can I convert CTime object to string?
- http://www.microsoft.com/mobile/developer/technicalarticles/datetimecplus.asp
Article: Working with Dates and Times in C++