realtime HighPerformanceCounter information
gamerChad at _spamIsBad_gmail.com
Tue Nov 21 17:47:40 PST 2006
>>>Is it possible to get timing information before stopping a timer?
>>>Something like this:
>>>HighPerformanceCounter c = new HighPerformanceCounter();
>>>When I do this now, c.microseconds() returns some 'random number :(
>>I'm curious, why do you need to keep the timer running?
> I hoped to use it for timing my main loop :)
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:
private HighPerformanceCounter hpc;
private ulong runningTime = 0;
public ulong microseconds()
runningTime += hpc.microseconds();
public void reset()
runningTime = 0;
hpc = new HighPerformanceCounter();
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