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]
In reply to How to sleep 1 microsecond? by sophate
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |