in reply to Time::HiRes sleep does not always work

UPDATE Try this to see what is happening:
sub sleepy { my $count = shift; my $time = gettimeofday; sleep(0.0001); # Sleep here to ensure unique time my $hitime = gettimeofday; print $time - $hitime,' '; if ( $time == $hitime ) { $match++; } }

I think you are running into some real world factors affecting computers(desktops/laptops). Although we all like to assume that our little machines maintain atomic clock, laboratory quality, time; it's not true. A computer has a little imperfect crystal, that maintains it's time. The crystal is not even temperature stabilized, meaning your clock rate varies with temperature. It's not enough for us to notice, unless there is a bad failure, and the computer circuitry is designed to work with the variations, by using edges of clock waves for synchronization.

You also have the kernel's design to consider. There are different schedulers, and the one you would want to use would be the low-latency kernel, that audiophiles use. Otherwise, your kernel may decide to spend a few microseconds updating your display, rather than process your script.

Our computers seem like superfast machines to us, but in a true measure of time, they slog along like they were mired in molasses.


I'm not really a human, but I play one on earth Remember How Lucky You Are

Replies are listed 'Best First'.
Re^2: Time::HiRes sleep does not always work
by tone (Novice) on Aug 18, 2008 at 10:09 UTC

    If I put in your changes to the routine I get 2000 matches.

    So do you think that the reason that the laptops like mine are having this problem could be caused because they are made from lower quality components than say a Dell?

      That's my GUESS, the timer support chips in your laptop either are partially defective, or poor quality( low speed). Or some other factor on your motherboard interferes. But after reading tilly's responses, maybe there is some problem in the kernel your slow laptop is using.

      I'm not really a human, but I play one on earth Remember How Lucky You Are