http://www.perlmonks.org?node_id=987933


in reply to Re: How to sleep 1 microsecond?
in thread How to sleep 1 microsecond?

One microsecond should be 1000 nanoseconds.


Dave

Replies are listed 'Best First'.
Re^3: How to sleep 1 microsecond?
by sophate (Beadle) on Aug 17, 2012 at 08:15 UTC

    Hi, the sample codes above use usleep. Here is the program using nanosleep.

    #!/usr/bin/perl use strict; use warnings; use Time::HiRes qw(usleep nanosleep gettimeofday); my @start = gettimeofday (); my $sleep = nanosleep(1000); my @end = gettimeofday (); print "[$sleep][@start][@end]\n"; Results: [1000][1345190945 846575][1345190945 846739]

    Compared with the codes that just get the timestamps two times(without the nanosleep line). The nanosleep actually sleeps much longer than 1 microsecond.

    #!/usr/bin/perl use strict; use warnings; use Time::HiRes qw(usleep nanosleep gettimeofday); my @start = gettimeofday (); my @end = gettimeofday (); print "[@start][@end]\n"; Results: [1345190988 610721][1345190988 610723]
Re^3: How to sleep 1 microsecond?
by influx (Beadle) on Aug 17, 2012 at 08:16 UTC
    You're totally right, sorry. I just checked Google!