Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: How to sleep 1 microsecond?

by influx (Beadle)
on Aug 17, 2012 at 07:57 UTC ( #987931=note: print w/replies, xml ) Need Help??


in reply to How to sleep 1 microsecond?

Did you actually try nanosleep(1000000); ? I didn't see that in your sample.

Replies are listed 'Best First'.
Re^2: How to sleep 1 microsecond?
by davido (Archbishop) on Aug 17, 2012 at 08:06 UTC

    One microsecond should be 1000 nanoseconds.


    Dave

      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]
      You're totally right, sorry. I just checked Google!

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://987931]
help
Chatterbox?
[choroba]: csh considered harmful
[erix]: no, I'm using bash :)
[marioroy]: :)
[marioroy]: I use the default and happens to be bash
[erix]: heh, I like the "Resolved" (Christiansen is really funny)
Discipulus is makita a reincarnation of grinder?
[erix]: I probably also need to understand TAP a bit better than I do

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (8)
As of 2017-03-23 08:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Should Pluto Get Its Planethood Back?



    Results (285 votes). Check out past polls.