Timing

Hello.

Is there a way to count milliseconds, using console applications?

So far, I've been using time_t.
1
2
3
4
5
6
7
8
time_t seconds;
int clocker;
time_t seconds2;
seconds = time (NULL);
_getch();
seconds2 = time (NULL);
clocker = (seconds2 - seconds)*1000; 
cout << clocker;

And the console sees out:
1000

Though, thats too inexact.

Is there a better way to do it?


Thanks!

Edit: Grammar.
Last edited on
No really platform independent one. However, on windows you can use GetTickCount:
http://msdn.microsoft.com/en-us/library/ms724408%28v=vs.85%29.aspx

Other than that, you can also use clock from ctime: http://www.cplusplus.com/reference/clibrary/ctime/clock/
Thank you.
Topic archived. No new replies allowed.