realtime HighPerformanceCounter information

Lutger lutger.blijdestijn at gmail.com
Tue Nov 21 19:06:33 PST 2006


nobody_ wrote:
> I've just been checking the souce code of  std.perf and I can't see why it 
> isn't:
> 
> interval_type periodCount()
> {
>     if(running){
>         return m_end - m_start;
>     }else{
>         QueryPerformanceCounter(&m_inter);
>          return m_inter - m_start;
>     }
> }
> 
> If the counter doesn't take any more resources than its starting value, 
> stop() can be left out totally
> and the code would be as simple as this :)
> 
> interval_type periodCount()
> {
>         QueryPerformanceCounter(&m_inter);
>          return m_inter - m_start;
> }

periodCount does not return the time, but the number of ticks. To get 
the time in seconds you have to divide by the frequency, which is 
represented by sm_freq in std.perf. The other stuff is for adjusting to 
milli- and microseconds and not getting rounding errors.

I believe this (HighPerformanceCounter) is windows-only code though.

> If I were into object programming, I might even be able to implement it.
> But as I'm not into it, it might just be a bad idea ;)

Or not, it might just be simple and fun to do. A timer could very well 
be a single tiny function that returns the time since application was 
loaded or whatever, no object orientation needed at all.



More information about the Digitalmars-d-learn mailing list