sophate has asked for the wisdom of the Perl Monks concerning the following question:
Dear Monks,
I'm writing some codes that need to sleep for a very short time, say 1 microsecond. I tried "Time-HiRes" and used "usleep" or "nanosleep". However, usleep and nanosleep actually sleep much longer than 1 microsecond. From the returned value of the function calls, they sleep about 1 milisecond(1000 microseconds) even though I specify the sleep interval to 1 microsecond. Here is my program. Any suggestions how I can force my Perl program to sleep about 1 microsecond? Thanks in advance.
#!/usr/bin/perl use strict; use warnings; use Time::HiRes qw(usleep nanosleep gettimeofday); my @start = gettimeofday (); my $sleep = usleep(1); my @end = gettimeofday (); print "[$sleep][@start][@end]\n"; --------------------------------------- Sample Results: [805][1345188496 560216][1345188496 561029]
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: How to sleep 1 microsecond?
by moritz (Cardinal) on Aug 17, 2012 at 08:12 UTC | |
|
Re: How to sleep 1 microsecond?
by GrandFather (Saint) on Aug 17, 2012 at 08:06 UTC | |
by Anonymous Monk on Aug 17, 2012 at 08:13 UTC | |
by sophate (Beadle) on Aug 18, 2012 at 10:21 UTC | |
by sophate (Beadle) on Aug 18, 2012 at 10:23 UTC | |
|
Re: How to sleep 1 microsecond?
by lidden (Curate) on Aug 17, 2012 at 13:15 UTC | |
|
Re: How to sleep 1 microsecond?
by influx (Beadle) on Aug 17, 2012 at 07:57 UTC | |
by davido (Cardinal) on Aug 17, 2012 at 08:06 UTC | |
by sophate (Beadle) on Aug 17, 2012 at 08:15 UTC | |
by influx (Beadle) on Aug 17, 2012 at 08:16 UTC | |
|
Re: How to sleep 1 microsecond?
by Lotus1 (Vicar) on Aug 17, 2012 at 18:07 UTC | |
|
Re: How to sleep 1 microsecond?
by influx (Beadle) on Aug 17, 2012 at 08:31 UTC | |
by davido (Cardinal) on Aug 17, 2012 at 08:46 UTC | |
by influx (Beadle) on Aug 17, 2012 at 08:56 UTC | |
|
Re: How to sleep 1 microsecond?
by tobyink (Canon) on Aug 17, 2012 at 16:36 UTC | |
by sophate (Beadle) on Aug 18, 2012 at 10:42 UTC | |
by tobyink (Canon) on Aug 18, 2012 at 11:27 UTC | |
|
Re: How to sleep 1 microsecond?
by locked_user sundialsvc4 (Abbot) on Aug 17, 2012 at 12:38 UTC |