I\'m writing a portable Socket class that supports timeouts for both sending and receiving... To implement these timeouts I\'m using select()
.... But, I sometim
How about:
unsigned long start = GetTickCount();
// stuff that needs to be timed
unsigned long delta = GetTickCount() - start;
GetTickCount()
is not very precise, but will probably work well. If you see a lot of 0, 16 or 31 millisecond intervals, try timing over longer intervals or use a more precise function like timeGetTime
.
What I usually do is this:
unsigned long deltastack;
int samples = 0;
float average;
unsigned long start = GetTickCount();
// stuff that needs to be timed
unsigned long delta = GetTickCount() - start;
deltastack += delta;
if (samples++ == 10)
{
// total time divided by amount of samples
average = (float)deltastack / 10.f;
deltastack = 0;
samples = 0;
}