The problem is that my program is so fast that it doesn't detect change in time, or GetTickCount(), how can i prevent this from happening?
Thank You
The problem is that my program is so fast that it doesn't detect change in time, or GetTickCount(), how can i prevent this from happening?
Thank You
Are you printing the running time as an integer? If you are doing division to get the elapsed time, cast the numerator or denominator as a float.
Time how long x
runs take and take an average.
Additionally you can use profiling for an accurate timing.
Use
void WINAPI GetSystemTimeAsFileTime(
_Out_ LPFILETIME lpSystemTimeAsFileTime
);
instead. It has better resolution. In majority of cases this is really what is needed.
There's a very handy class on CodeProject that wraps QueryPerformanceCounter
, that I use often: http://www.codeproject.com/Articles/475/The-CPerfTimer-timer-class
GetTickCount has 5..15 millisecond precision, so "zero time difference" is a common problem.
If you need precision, use QueryPerformanceCounter.
Or you can try using rtdsc. for details see here: http://www.mcs.anl.gov/~kazutomo/rdtsc.html Snippet:
#include <stdio.h>
#include "rdtsc.h"
int main(int argc, char* argv[])
{
unsigned long long a,b;
a = rdtsc();
b = rdtsc();
printf("%llu\n", b-a);
return 0;
}
Or even chrono is good, but then it needs C++11 compliance (in part). details: std::chrono and cout