in reply to Re^4: Unexpected Timing spikes using Time::HiRes
in thread Unexpected Timing spikes using Time::HiRes
I'm unable to reproduce your results on Vista, but it uses a different scheduling mechanism. It occassionally takes a little longer than 1 second to wake up, but only by 1 or 2 milliseconds at most. Even running at standard priority.
I think that what you are seeing is simply an affect of timing.
XP (and as far as I know 200x) use a hardware timer of approx. 15ms for the scheduler. If your process is due to wake up from it's 1 second sleep a few microseconds after another, cpu-intensive process gets it 15ms timeslot, then by the time your process next gets a chance to run, it will be 1.0015 + a little bit since the sleep was initiated.
Running at the highest priority means your process will get the next available timeslot, but it won't allow it to interrupt the current timeslot.
I'm not certain that's a convincing explanation, but it is the best I have.
Basically, trying to time anything to sub millisecond accuracy on a pre-emptive multi-tasking OS will inevitably sometimes be subverted by the scheduler allowing another task to run just when you want to collect your timing.
Depending what it is that you are trying to time--real-world events -v- code--then you might be better off using the cpus instruction timer.
Out of interest, which version of Time::HiRes are you running?
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^6: Unexpected Timing spikes using Time::HiRes
by desemondo (Hermit) on Jan 21, 2010 at 01:49 UTC | |
by BrowserUk (Patriarch) on Jan 21, 2010 at 02:17 UTC | |
by desemondo (Hermit) on Jan 21, 2010 at 22:34 UTC | |
by BrowserUk (Patriarch) on Jan 22, 2010 at 01:51 UTC |