Jump to content
Tuts 4 You
CodeExplorer

Looking for PreciseTimer.zip - Visual C++

Recommended Posts

CodeExplorer
CodeExplorer

Never mind I was able to download now the file.
(attached)!
 

701793291PreciseTimer.zip

  • Thanks 1

Share this post


Link to post
Share on other sites
CodeExplorer

On the second post it was time measurement, maybe some one will need that.

I've created class PreciseTimer from first post, first link (attached).
And some usage here:

void CAlocLogDlg::OnButton9()
{
    // TODO: Add your control notification handler code here

for (int i=0;i<2000000000;i++)
{
PreciseTimer* pt = new PreciseTimer();

LARGE_INTEGER iStart, iStop;
QueryPerformanceCounter(&iStart);

pt->Wait(5); // is there anything to wait on? ... then wait
QueryPerformanceCounter(&iStop);

long diference = (long)iStop.QuadPart-(long)iStart.QuadPart;

if (diference>5)
{
int no_way = 1;
}


}

}

 

PreciseTimer.zip

  • Thanks 1

Share this post


Link to post
Share on other sites
CodeExplorer

timeSetEvent https://msdn.microsoft.com/en-us/library/windows/desktop/dd757634(v=vs.85).aspx
suppose to be precise
 

void CALLBACK TimerFunction(UINT wTimerID, UINT msg,
    DWORD dwUser, DWORD dw1, DWORD dw2)
    {

char conv_str[50];
wsprintf(conv_str,"%d", GetTickCount());  // convert number to dec string
InsertStringToList(conv_str);

    }

void CAlocLogDlg::OnButton9()
{
// TODO: Add your control notification handler code here

// https://msdn.microsoft.com/en-us/library/windows/desktop/dd757634%28v=vs.85%29.aspx
MMRESULT m_idEvent = timeSetEvent(1, 0,
        TimerFunction,
        (DWORD)this,
        TIME_PERIODIC);
}

Actually is not precise at all! Still maybe someone will find the solutions posted above useful, but not me!

The best solution I found so far is CreateThread on an infinite loop:
 

DWORD   dwThreadId;
HANDLE hThread = CreateThread(
            NULL,                   // default security attributes
            0,                      // use default stack size  
            MyThreadFunction,       // thread function name
            NULL,          // argument to thread function
            0,                      // use default creation flags
            &dwThreadId);   // returns the thread identifier 

But there is a problem: to many CPU resource are consumed.
I've thinked at something like if the time passed since last value found has a specific value do Sleep(1).

 

Share this post


Link to post
Share on other sites
CodeExplorer

So here is my solution:
LastTimeValueFound = GetTickCount();
called twice after each variable was readed,

and on the loop I do this:

if (LastTimeValueFound==0||(GetTickCount()-LastTimeValueFound)>100)
{
Sleep(1);
}

CPU usage was once 20% for a short time - when Api logged,
When no Api logged 0% CPU usage,
tracing time 2 minutes for a nasty Asprotect unpackme.
 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×