0

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

Robᵩ
  • 163,533
  • 20
  • 239
  • 308
Miguel P
  • 1,262
  • 6
  • 23
  • 48
  • 1
    You can try something more precise if it's taking less than a millisecond. `QueryPerformanceCounter` would be a good start, or the new-ish `` header. – chris Nov 17 '12 at 01:46

6 Answers6

0

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.

Chris
  • 4,663
  • 5
  • 24
  • 33
0

Time how long x runs take and take an average.

Additionally you can use profiling for an accurate timing.

Casey
  • 10,297
  • 11
  • 59
  • 88
0

Use

void WINAPI GetSystemTimeAsFileTime(
  _Out_  LPFILETIME lpSystemTimeAsFileTime
);

instead. It has better resolution. In majority of cases this is really what is needed.

Kirill Kobelev
  • 10,252
  • 6
  • 30
  • 51
0

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

Jonathan Potter
  • 36,172
  • 4
  • 64
  • 79
0

GetTickCount has 5..15 millisecond precision, so "zero time difference" is a common problem.

If you need precision, use QueryPerformanceCounter.

SigTerm
  • 26,089
  • 6
  • 66
  • 115
-2

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

Community
  • 1
  • 1
Sarang
  • 1,867
  • 1
  • 16
  • 31