realtime HighPerformanceCounter information
nobody_
spam at spam.spam
Tue Nov 21 18:38:03 PST 2006
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;
}
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 ;)
> Hmmm, well unless there are bizarre realtime low-level type conditions
> that must be met, then I'd suggest doing what Lutger just mentioned - wrap
> D's timer into your own that allows you to do what you want.
> Perhaps something like this:
>
> class MyTimer
> {
> private HighPerformanceCounter hpc;
> private ulong runningTime = 0;
>
> public ulong microseconds()
> {
> hpc.stop();
> runningTime += hpc.microseconds();
> hpc.start();
> return runningTime;
> }
>
> public void reset()
> {
> hpc.stop();
> hpc.start();
> runningTime = 0;
> }
>
> this()
> {
> hpc = new HighPerformanceCounter();
> hpc.start();
> }
> }
>
> Now your code becomes something like this:
>
> MyTimer timer = new MyTimer();
> while( timer.microseconds < 1000 )
> {
> // ... do whatever ...
> }
>
> IMO Phobo's current timer setup is a bit too low level and barely
> documented for normal use. std.perf is also a poor name for a timing
> module. It'd be nice to see a timer class/struct similar to the one I
> just wrote (but much much more feature rich of course) implemented in
> phobos, perhaps in a seperate std.timer module (which means std.perf can
> stay as it is, and it probably won't bother anyone).
More information about the Digitalmars-d-learn
mailing list