But out of curiosity, how would you see that it did pause for 10ms (it is less than a f** sec)?
Anyway the thing i gave you, can be test if you set $time = 100/10; just to see that it works, this will pause it for ten seconds, after relising that 'yes it does work' set '$time = 10/1000; and see the difference "Quick EYE"!
The sleep function only works with integers. I don't know the exact internals of it but it's as if it runs the argument through the int function first (i.e. rounds it down to the previous integer value). Time::HiRes would be the way to go. If you've used something like "sleep 0.01", just add the following line to the top of your script:
Code:
use Time::HiRes qw( sleep );
That imports the Time::HiRes::sleep() function which replaces the builtin sleep function.
perluserpengo - both the builtin sleep() and Time::HiRes::sleep() return the number of seconds it slept for. e.g.:
oh i see..
sleep round the time 0.5->0 , 1.5->1
ok my bad.
But the Time::HiRes::sleep gives multiple results if you test it a lot of times
for $time = 3/2 it gives
1.498657
1.498611
1.498654
1.514205
1.498548
and as many times you check you gonna get a different number,
do you know why this is happening?
I'd suggest that 1.5 can't be taken as the only thing the CPU will recognise, as there are other processes running on the machine, and these need to be scheduled, but they are within 1.5% (1.42% actually) of the intended time, and mostly lower.
If you used a finer grain, the results might be closer to what is expected.
I'd further suggest that for any sleep function to work as expected it would need to be the only process on the machine, including the OS, but I could be talking out of my a** ;-)
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.