How can i count the millisecond a certain function (called repeatedly) takes ?
I thought of:
CTime::GetCurrentTM()
before,
CTime::GetCurrentTM()
after,
And then insert the result to CTimeSpan diff = after - before
.
Finally store that diff to global member that sum all diffs since i want to know the total time this function spent.
but it will give the answer in seconds and not milliseconds.
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 will usually give you millisecond precision.