How to calculate a operation's time in micro second precision

Posted by Sanjeet Daga on Stack Overflow See other posts from Stack Overflow or by Sanjeet Daga
Published on 2010-05-13T13:03:56Z Indexed on 2010/05/13 13:14 UTC
Read the original article Hit count: 275

Filed under:
|
|
|

I want to calculate performance of a function in micro second precision on Windows platform.

Now Windows itself has milisecond granuality, so how can I achieve this.

I tried following sample, but not getting correct results.

LARGE_INTEGER ticksPerSecond = {0};
LARGE_INTEGER tick_1 = {0};
LARGE_INTEGER tick_2 = {0};
double uSec = 1000000;

// Get the frequency
QueryPerformanceFrequency(&ticksPerSecond);

//Calculate per uSec freq
double uFreq = ticksPerSecond.QuadPart/uSec;

// Get counter b4 start of op
QueryPerformanceCounter(&tick_1);

// The ope itself
Sleep(10);

// Get counter after opfinished
QueryPerformanceCounter(&tick_2);

// And now the op time in uSec
double diff = (tick_2.QuadPart/uFreq) - (tick_1.QuadPart/uFreq);

© Stack Overflow or respective owner

Related posts about c

    Related posts about c++