My GetTickCount() seems to always return the same value.
Has this happened to you ? :confused:
Printable View
My GetTickCount() seems to always return the same value.
Has this happened to you ? :confused:
Yes, for something like:Put a call to 'Sleep' in before the GetTickCount call and it will update. This is because GetTickCount is not very accurate.Code:#include <windows.h>
#include <iostream>
int main()
{
int i=200;
while (i)
{
std::cout<<GetTickCount()<<"\n";
--i;
}
std::cout<<std::endl;
}
If you need a more precise timer then you can get millisecond precision with timeGetTime (if you set the period to 1ms with timeBeginPeriod). Windows also has high resolution timers but these may not be available with older machines - see QueryPerformanceCounter and QueryPerformanceFrequency. Search the boards, too, for these functions and 'timing'; I suspect you'll find previous discussions on the subject of timing that may be of interest.
Yea GetTickCount will return the same value within the same millisecond. If you are using it to compare the speed of two functions, I would suggest putting the two functions in a for loop for about 10000 times or so, then comparing the running length of those two loops, it will be much more acurate.
If you are timing something that has a smaller resolution than a millisecond, you can use a high resolution performance timer. See QueryPerformanceCounter().