Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re^3: How to sleep 1 microsecond?

by sophate (Beadle)
on Aug 17, 2012 at 08:15 UTC ( #987936=note: print w/ replies, xml ) Need Help??


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

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]


Comment on Re^3: How to sleep 1 microsecond?
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://987936]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (8)
As of 2015-07-29 23:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (269 votes), past polls