MFC measurement function in milliseconds

How can I count a millisecond when a certain function (called repeatedly) takes?
I thought:
CTime::GetCurrentTM() before,
CTime::GetCurrentTM() after,

And then paste the result into CTimeSpan diff = after - before .
Lastly, save this diff for the global member that sums up all the diff, since I want to know the total time this function takes.

but it will give an answer in seconds, not milliseconds.

+6
source share
3 answers

MFC is C ++, right?

If so, you can just use clock() .

 #include <ctime> clock_t time1 = clock(); // do something heavy clock_t time2 = clock(); clock_t timediff = time2 - time1; float timediff_sec = ((float)timediff) / CLOCKS_PER_SEC; 

This usually gives you millisecond accuracy.

+6
source

If you use MFC, a good way is to use the WIN API. And since you are worried just to calculate the time difference, the function below may suit you.

 GetTickCount64() 

returns the number of milliseconds elapsed since the system started.

If you do not plan to hold your system for a long time (exactly more than 49.7 days), a little faster is the GetTickCount () function

+1
source

It is known that COleDateTime performs internal work on the basis of milliseconds, because it stores the timestamp for the variable m_dt, which is of type DATE, and therefore has permission as intended.

I can offer you to base your time on

 DATE now= (DATE) COleDateTime::GetCurrentTime(); 

and after appropriate calculations.

0
source

All Articles