I need to find out the time elapsed between 2 events. Can someone help me with it. An example would be great.
Thanks in advance.
Printable View
I need to find out the time elapsed between 2 events. Can someone help me with it. An example would be great.
Thanks in advance.
I have attached a class that wraps some API calls to make dealing with time a little easier.
To use it
Code:#include "Timeout.h"
class MyClass
{
CTimeout m_to;
void OnEvent();
}
void CMyClass::OnEvent()
{
if (m_to.IsStarted())
m_to.Start();
else
printf( "%d", m_to.TimeElapsed() );
}
Hello,
What will be the order of time? One can use CTime::GetCurrentTime function to get the time as CTime and use CTime::GetAsSystemTime function to convert the time to a value of type SYSTEMTIME. wMilliseconds member of SYSTEMTIME structure can be used to get the time in milliseconds.
One can use the function GetTickCount to get the milliseconds elapsed since the system is started.
If you want to clock the events more accurately, you can use the function QueryPerformanceCounter in conjuction with the function QueryPerformanceFrequency.
Regards. Please rate this post if this suggestion is helpful.
Pravin.
04-05-2005.
Hello,
Here is a function which returns the time difference in seconds between its call and the previous call.
If it is called the first time, return value is 0. If there is no high-resolution performance counter, it returns 0 each time.Code:
float DTime()
{
static LARGE_INTEGER OldCounter = {0, 0};
LARGE_INTEGER Counter, Frequency;
if (QueryPerformanceFrequency(&Frequency))
{
QueryPerformanceCounter(&Counter);
float TimeDiff = OldCounter.LowPart ? (float)
(Counter.LowPart - OldCounter.LowPart) / Frequency.LowPart : 0;
OldCounter = Counter;
return TimeDiff;
}
else
return 0;
}
Does it help?
Pravin.
04-05-2005.
Thank you guys very much.