Sign in to follow this  
sathenzar

timing events...

Recommended Posts

sathenzar    100
Hey, I wanted to know if there was a function to get the amount of seconds the application of mine has been running. GetTickCount doesn't work, b/c it just generates milliseconds which isn't accurate b/c every second is like some odd 54,000 milliseconds when u use it. So is there a way where I could have an int time = sometimefuction();? I'm trying to create a timing even so every few seconds it does a different action. Thanks in advance.

Share this post


Link to post
Share on other sites
Wavarian    850
Hmmm.. That's strange.. Since there are only 1000 milliseconds in a second. Anyhow, you could look into a high resolution timer:


#include <windows.h>

void main() {

LARGE_INTEGER freq,start,stop;

// Initialize the "timer"
QueryPerformanceFrequency(&freq);

// Start the "timer"
QueryPerformanceCounter(&start);

// Do stuff
...

// Stop the timer
QueryPerformanceCounter(&stop);

int secondsElapsed = int((stop.QuadPart - start.QuadPart) / float(freq.QuadPart));
}

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

Sign in to follow this