Hello,

For an application I am writing I am time stamping each byte as it comes in.
I am using the following code to read in the byte and record it as it comes
in. I then find the difference between the times at which the bytes came and
build a new array of time differences. The only thing is that sometimes I get
negative values within this differential time array which doesnâ??t make much
sense to me. Other times Iâ??ll get almost all negative values with a few
positive ones.

The only reasons I can think of is that the performance counter loops around
and the occasional negative value is the result of this. But, does that
explain the times when I get a majority of negative values with a few
positives? If I replace the ReadFile with a sleep(10) I get times that make
sense.

Hereâ??s a stripped down version of my code:

LARGE_INTEGER times[1000];
LARGE_INTEGER time;

if (WaitCommEvent(m_hIRPort, &commEvent, NULL)) {
while (numRead && bufNdx < 1000) {
ReadFile(m_hIRPort, buffer + bufNdx, 1, &numRead, NULL);
QueryPerformanceCounter(&time);
times[bufNdx] = time;
bufNdx++;
}
}

__int64 adjTimes[1000];
for (int ndx = 1; ndx < bufNdx; ndx++)
adjTimes[ndx] = 1000000 * (times[ndx].QuadPart - times[ndx-1].QuadPart)
/ freq.QuadPart;


Kyle

Re: Negative difference between QueryPerformanceCounter values by Chris

Chris
Thu Mar 10 12:53:11 CST 2005

Not sure the exact reason, but I've seen the same in a tight loop on QPC -
adding a Sleep eliminates it - so it's not just you.

--
Chris Tacke
Co-founder
OpenNETCF.org
Has OpenNETCF helped you? Consider donating to support us!
http://www.opennetcf.org/donate


"ksmith" <ksmith@discussions.microsoft.com> wrote in message
news:B57C238F-7380-447D-8F11-3500BA41185F@microsoft.com...
> Hello,
>
> For an application I am writing I am time stamping each byte as it comes
> in.
> I am using the following code to read in the byte and record it as it
> comes
> in. I then find the difference between the times at which the bytes came
> and
> build a new array of time differences. The only thing is that sometimes I
> get
> negative values within this differential time array which doesn't make
> much
> sense to me. Other times I'll get almost all negative values with a few
> positive ones.
>
> The only reasons I can think of is that the performance counter loops
> around
> and the occasional negative value is the result of this. But, does that
> explain the times when I get a majority of negative values with a few
> positives? If I replace the ReadFile with a sleep(10) I get times that
> make
> sense.
>
> Here's a stripped down version of my code:
>
> LARGE_INTEGER times[1000];
> LARGE_INTEGER time;
>
> if (WaitCommEvent(m_hIRPort, &commEvent, NULL)) {
> while (numRead && bufNdx < 1000) {
> ReadFile(m_hIRPort, buffer + bufNdx, 1, &numRead, NULL);
> QueryPerformanceCounter(&time);
> times[bufNdx] = time;
> bufNdx++;
> }
> }
>
> __int64 adjTimes[1000];
> for (int ndx = 1; ndx < bufNdx; ndx++)
> adjTimes[ndx] = 1000000 * (times[ndx].QuadPart -
> times[ndx-1].QuadPart)
> / freq.QuadPart;
>
>
> Kyle
>



Re: Negative difference between QueryPerformanceCounter values by The

The
Fri Mar 11 05:27:09 CST 2005

From our long experience with Pocket PC: QueryPerformanceCounter is quite
bogus and un-reliable, and it will not give you a timing more accurate that
GetTickCount (in milliseconds)

I would not be surprise that the lsb bits (i.e. the part more accurate that
one millisesecond) is in fact completely random, causing inconsistent timing
(i.e. a call later will return an earlier time.

Apparently MSFT does not provide OEM's with a good test to test that
QueryPerformanceCounter works on their platform.

We have even seen some Smartphones from a very famous operator (Orange) on
which QueryPerformanceCounter was returning time elapsing at totally an
incorrect rate!

So if you want some advice: don't use QueryPerformanceCounter, it will only
bring you troubles. Use GetTickCount, that's known to work.


"ksmith" <ksmith@discussions.microsoft.com> wrote in message
news:B57C238F-7380-447D-8F11-3500BA41185F@microsoft.com...
> Hello,
>
> For an application I am writing I am time stamping each byte as it comes
> in.
> I am using the following code to read in the byte and record it as it
> comes
> in. I then find the difference between the times at which the bytes came
> and
> build a new array of time differences. The only thing is that sometimes I
> get
> negative values within this differential time array which doesn't make
> much
> sense to me. Other times I'll get almost all negative values with a few
> positive ones.
>
> The only reasons I can think of is that the performance counter loops
> around
> and the occasional negative value is the result of this. But, does that
> explain the times when I get a majority of negative values with a few
> positives? If I replace the ReadFile with a sleep(10) I get times that
> make
> sense.
>
> Here's a stripped down version of my code:
>
> LARGE_INTEGER times[1000];
> LARGE_INTEGER time;
>
> if (WaitCommEvent(m_hIRPort, &commEvent, NULL)) {
> while (numRead && bufNdx < 1000) {
> ReadFile(m_hIRPort, buffer + bufNdx, 1, &numRead, NULL);
> QueryPerformanceCounter(&time);
> times[bufNdx] = time;
> bufNdx++;
> }
> }
>
> __int64 adjTimes[1000];
> for (int ndx = 1; ndx < bufNdx; ndx++)
> adjTimes[ndx] = 1000000 * (times[ndx].QuadPart -
> times[ndx-1].QuadPart)
> / freq.QuadPart;
>
>
> Kyle
>