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ᵩ
  • 154,489
  • 17
  • 222
  • 296
Miguel P
  • 1,192
  • 5
  • 21
  • 45
  • 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,203
  • 4
  • 22
  • 32
0

Time how long x runs take and take an average.

Additionally you can use profiling for an accurate timing.

Casey
  • 9,380
  • 11
  • 57
  • 81
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
  • 9,986
  • 6
  • 27
  • 48
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
  • 35,093
  • 4
  • 58
  • 73
0

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

If you need precision, use QueryPerformanceCounter.

SigTerm
  • 25,518
  • 5
  • 63
  • 112
-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,837
  • 1
  • 16
  • 31