Click here to Skip to main content
15,892,161 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
HI I need to get the time difference in seconds in win32 .

Eg: I have a function . i have to get the time in sec the function has taken to execute . I tried using GetTickCount() , but thats not helping out.
Posted

1 solution

You did not explain why GetTickCount() is not working for you. If you call GetTickCount() before you execute your function and again after, subtracting the start value from the end value returns the elapsed time in ms.

It is really quite trivial:
C++
DWORD startCount = GetTickCount();

// Run your funciton here.

DWORD endCount = GetTickCount();

DWORD timeSpan = end - start;


Perhaps your problem is that the result is not accurate enough - this is quite common if your function executes fast enough. In that case, you can try out QueryPerformanceCounter(). It is a little more complex to work with but has a much higher accuracy.

If you Google QueryPerformanceCounter() you will find lots of hits, such as
A C++ class for more precise time interval measurement[^]
Here is an MSDN article[^]
Here is a discussion on StackOverflow[^]


Soren Madsen
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900