High res timer

J

Jon Slaughter

Lit said:
Just wondering does the counters acts as a Timer Interrupt ( old
assembly )?

Lit

I'm not sure what you mean but essentially the counter function is suppose
to act sorta like a timer that has better than millisecond accuracy.

Essentially what I do is time how fast the thread is able to count. So if it
counts N in 3 seconds then obviously N/3 is the frequency at which the
thread is running and 3/N is how fast it was able to count up to that point.

The delayer part is to slow down the counter to get an adjustable frequency.

The issues are obviously that you are wasting cpu and that the counter isn't
very stable in some cases. But for my app its not all that serious because
I'll only be using the thread for very short periods of time.

Jon
 
B

Ben Voigt [C++ MVP]

In fact, I'm wondering if you can't use the new StopWatch class which uses
QueryPerformanceCounter internally): Something like:

Stopwatch s = Stopwatch.StartNew();
while (s.ElapsedTicks / StopWatch.Frequency < requiredTimeToWaitInSeconds)

better:

long ticksToWait = StopWatch.Frequency * requiredTimeToWaitInSeconds;
while (s.ElapsedTicks < ticksToWait)

Never divide when you can multiply :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top