📄 time::hires.3
字号:
.\" Automatically generated by Pod::Man 2.16 (Pod::Simple 3.05).\".\" Standard preamble:.\" ========================================================================.de Sh \" Subsection heading.br.if t .Sp.ne 5.PP\fB\\$1\fR.PP...de Sp \" Vertical space (when we can't use .PP).if t .sp .5v.if n .sp...de Vb \" Begin verbatim text.ft CW.nf.ne \\$1...de Ve \" End verbatim text.ft R.fi...\" Set up some character translations and predefined strings. \*(-- will.\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left.\" double quote, and \*(R" will give a right double quote. \*(C+ will.\" give a nicer C++. Capital omega is used to do unbreakable dashes and.\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff,.\" nothing in troff, for use with C<>..tr \(*W-.ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'.ie n \{\. ds -- \(*W-. ds PI pi. if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch. if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch. ds L" "". ds R" "". ds C` "". ds C' ""'br\}.el\{\. ds -- \|\(em\|. ds PI \(*p. ds L" ``. ds R" '''br\}.\".\" Escape single quotes in literal strings from groff's Unicode transform..ie \n(.g .ds Aq \(aq.el .ds Aq '.\".\" If the F register is turned on, we'll generate index entries on stderr for.\" titles (.TH), headers (.SH), subsections (.Sh), items (.Ip), and index.\" entries marked with X<> in POD. Of course, you'll have to process the.\" output yourself in some meaningful fashion..ie \nF \{\. de IX. tm Index:\\$1\t\\n%\t"\\$2"... nr % 0. rr F.\}.el \{\. de IX...\}.\".\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2)..\" Fear. Run. Save yourself. No user-serviceable parts.. \" fudge factors for nroff and troff.if n \{\. ds #H 0. ds #V .8m. ds #F .3m. ds #[ \f1. ds #] \fP.\}.if t \{\. ds #H ((1u-(\\\\n(.fu%2u))*.13m). ds #V .6m. ds #F 0. ds #[ \&. ds #] \&.\}. \" simple accents for nroff and troff.if n \{\. ds ' \&. ds ` \&. ds ^ \&. ds , \&. ds ~ ~. ds /.\}.if t \{\. ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u". ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u'. ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u'. ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u'. ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u'. ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u'.\}. \" troff and (daisy-wheel) nroff accents.ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V'.ds 8 \h'\*(#H'\(*b\h'-\*(#H'.ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#].ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H'.ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u'.ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#].ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#].ds ae a\h'-(\w'a'u*4/10)'e.ds Ae A\h'-(\w'A'u*4/10)'E. \" corrections for vroff.if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u'.if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u'. \" for low resolution devices (crt and lpr).if \n(.H>23 .if \n(.V>19 \\{\. ds : e. ds 8 ss. ds o a. ds d- d\h'-1'\(ga. ds D- D\h'-1'\(hy. ds th \o'bp'. ds Th \o'LP'. ds ae ae. ds Ae AE.\}.rm #[ #] #H #V #F C.\" ========================================================================.\".IX Title "Time::HiRes 3".TH Time::HiRes 3 "2007-12-18" "perl v5.10.0" "Perl Programmers Reference Guide".\" For nroff, turn off justification. Always turn off hyphenation; it makes.\" way too many mistakes in technical documents..if n .ad l.nh.SH "NAME"Time::HiRes \- High resolution alarm, sleep, gettimeofday, interval timers.SH "SYNOPSIS".IX Header "SYNOPSIS".Vb 3\& use Time::HiRes qw( usleep ualarm gettimeofday tv_interval nanosleep\& clock_gettime clock_getres clock_nanosleep clock\& stat );\&\& usleep ($microseconds);\& nanosleep ($nanoseconds);\&\& ualarm ($microseconds);\& ualarm ($microseconds, $interval_microseconds);\&\& $t0 = [gettimeofday];\& ($seconds, $microseconds) = gettimeofday;\&\& $elapsed = tv_interval ( $t0, [$seconds, $microseconds]);\& $elapsed = tv_interval ( $t0, [gettimeofday]);\& $elapsed = tv_interval ( $t0 );\&\& use Time::HiRes qw ( time alarm sleep );\&\& $now_fractions = time;\& sleep ($floating_seconds);\& alarm ($floating_seconds);\& alarm ($floating_seconds, $floating_interval);\&\& use Time::HiRes qw( setitimer getitimer );\&\& setitimer ($which, $floating_seconds, $floating_interval );\& getitimer ($which);\&\& use Time::HiRes qw( clock_gettime clock_getres clock_nanosleep\& ITIMER_REAL ITIMER_VIRTUAL ITIMER_PROF ITIMER_REALPROF );\&\& $realtime = clock_gettime(CLOCK_REALTIME);\& $resolution = clock_getres(CLOCK_REALTIME);\&\& clock_nanosleep(CLOCK_REALTIME, 1.5e9);\& clock_nanosleep(CLOCK_REALTIME, time()*1e9 + 10e9, TIMER_ABSTIME);\&\& my $ticktock = clock();\&\& use Time::HiRes qw( stat );\&\& my @stat = stat("file");\& my @stat = stat(FH);.Ve.SH "DESCRIPTION".IX Header "DESCRIPTION"The \f(CW\*(C`Time::HiRes\*(C'\fR module implements a Perl interface to the\&\f(CW\*(C`usleep\*(C'\fR, \f(CW\*(C`nanosleep\*(C'\fR, \f(CW\*(C`ualarm\*(C'\fR, \f(CW\*(C`gettimeofday\*(C'\fR, and\&\f(CW\*(C`setitimer\*(C'\fR/\f(CW\*(C`getitimer\*(C'\fR system calls, in other words, highresolution time and timers. See the \*(L"\s-1EXAMPLES\s0\*(R" section below and thetest scripts for usage; see your system documentation for thedescription of the underlying \f(CW\*(C`nanosleep\*(C'\fR or \f(CW\*(C`usleep\*(C'\fR, \f(CW\*(C`ualarm\*(C'\fR,\&\f(CW\*(C`gettimeofday\*(C'\fR, and \f(CW\*(C`setitimer\*(C'\fR/\f(CW\*(C`getitimer\*(C'\fR calls..PPIf your system lacks \f(CW\*(C`gettimeofday()\*(C'\fR or an emulation of it you don'tget \f(CW\*(C`gettimeofday()\*(C'\fR or the one-argument form of \f(CW\*(C`tv_interval()\*(C'\fR.If your system lacks all of \f(CW\*(C`nanosleep()\*(C'\fR, \f(CW\*(C`usleep()\*(C'\fR,\&\f(CW\*(C`select()\*(C'\fR, and \f(CW\*(C`poll\*(C'\fR, you don't get \f(CW\*(C`Time::HiRes::usleep()\*(C'\fR,\&\f(CW\*(C`Time::HiRes::nanosleep()\*(C'\fR, or \f(CW\*(C`Time::HiRes::sleep()\*(C'\fR.If your system lacks both \f(CW\*(C`ualarm()\*(C'\fR and \f(CW\*(C`setitimer()\*(C'\fR you don't get\&\f(CW\*(C`Time::HiRes::ualarm()\*(C'\fR or \f(CW\*(C`Time::HiRes::alarm()\*(C'\fR..PPIf you try to import an unimplemented function in the \f(CW\*(C`use\*(C'\fR statementit will fail at compile time..PPIf your subsecond sleeping is implemented with \f(CW\*(C`nanosleep()\*(C'\fR insteadof \f(CW\*(C`usleep()\*(C'\fR, you can mix subsecond sleeping with signals since\&\f(CW\*(C`nanosleep()\*(C'\fR does not use signals. This, however, is not portable,and you should first check for the truth value of\&\f(CW&Time::HiRes::d_nanosleep\fR to see whether you have nanosleep, andthen carefully read your \f(CW\*(C`nanosleep()\*(C'\fR C \s-1API\s0 documentation for anypeculiarities..PPIf you are using \f(CW\*(C`nanosleep\*(C'\fR for something else than mixing sleepingwith signals, give some thought to whether Perl is the tool you shouldbe using for work requiring nanosecond accuracies..PPRemember that unless you are working on a \fIhard realtime\fR system,any clocks and timers will be imprecise, especially so if you are workingin a pre-emptive multiuser system. Understand the difference between\&\fIwallclock time\fR and process time (in UNIX-like systems the sum of\&\fIuser\fR and \fIsystem\fR times). Any attempt to sleep for X seconds willmost probably end up sleeping \fBmore\fR than that, but don't be surpisedif you end up sleeping slightly \fBless\fR..PPThe following functions can be imported from this module.No functions are exported by default..IP "gettimeofday ()" 4.IX Item "gettimeofday ()"In array context returns a two-element array with the seconds andmicroseconds since the epoch. In scalar context returns floatingseconds like \f(CW\*(C`Time::HiRes::time()\*(C'\fR (see below)..ie n .IP "usleep ( $useconds )" 4.el .IP "usleep ( \f(CW$useconds\fR )" 4.IX Item "usleep ( $useconds )"Sleeps for the number of microseconds (millionths of a second)specified. Returns the number of microseconds actually slept.Can sleep for more than one second, unlike the \f(CW\*(C`usleep\*(C'\fR system call.Can also sleep for zero seconds, which often works like a \fIthread yield\fR.See also \f(CW\*(C`Time::HiRes::usleep()\*(C'\fR, \f(CW\*(C`Time::HiRes::sleep()\*(C'\fR, and\&\f(CW\*(C`Time::HiRes::clock_nanosleep()\*(C'\fR..SpDo not expect \fIusleep()\fR to be exact down to one microsecond..ie n .IP "nanosleep ( $nanoseconds )" 4.el .IP "nanosleep ( \f(CW$nanoseconds\fR )" 4.IX Item "nanosleep ( $nanoseconds )"Sleeps for the number of nanoseconds (1e9ths of a second) specified.Returns the number of nanoseconds actually slept (accurate only tomicroseconds, the nearest thousand of them). Can sleep for more thanone second. Can also sleep for zero seconds, which often works likea \fIthread yield\fR. See also \f(CW\*(C`Time::HiRes::sleep()\*(C'\fR,\&\f(CW\*(C`Time::HiRes::usleep()\*(C'\fR, and \f(CW\*(C`Time::HiRes::clock_nanosleep()\*(C'\fR..SpDo not expect \fInanosleep()\fR to be exact down to one nanosecond.Getting even accuracy of one thousand nanoseconds is good..ie n .IP "ualarm ( $useconds\fR [, \f(CW$interval_useconds ] )" 4.el .IP "ualarm ( \f(CW$useconds\fR [, \f(CW$interval_useconds\fR ] )" 4.IX Item "ualarm ( $useconds [, $interval_useconds ] )"Issues a \f(CW\*(C`ualarm\*(C'\fR call; the \f(CW$interval_useconds\fR is optional andwill be zero if unspecified, resulting in \f(CW\*(C`alarm\*(C'\fR\-like behaviour..Sp\&\fIualarm\fR\|(0) will cancel an outstanding \fIualarm()\fR..SpNote that the interaction between alarms and sleeps is unspecified..IP "tv_interval" 4.IX Item "tv_interval"tv_interval ( \f(CW$ref_to_gettimeofday\fR [, \f(CW$ref_to_later_gettimeofday\fR] ).SpReturns the floating seconds between the two times, which should havebeen returned by \f(CW\*(C`gettimeofday()\*(C'\fR. If the second argument is omitted,then the current time is used..IP "time ()" 4.IX Item "time ()"Returns a floating seconds since the epoch. This function can beimported, resulting in a nice drop-in replacement for the \f(CW\*(C`time\*(C'\fRprovided with core Perl; see the \*(L"\s-1EXAMPLES\s0\*(R" below..Sp\&\fB\s-1NOTE\s0 1\fR: This higher resolution timer can return values either lessor more than the core \f(CW\*(C`time()\*(C'\fR, depending on whether your platformrounds the higher resolution timer values up, down, or to the nearest secondto get the core \f(CW\*(C`time()\*(C'\fR, but naturally the difference should be nevermore than half a second. See also \*(L"clock_getres\*(R", if availablein your system..Sp\&\fB\s-1NOTE\s0 2\fR: Since Sunday, September 9th, 2001 at 01:46:40 \s-1AM\s0 \s-1GMT\s0, whenthe \f(CW\*(C`time()\*(C'\fR seconds since epoch rolled over to 1_000_000_000, thedefault floating point format of Perl and the seconds since epoch haveconspired to produce an apparent bug: if you print the value of\&\f(CW\*(C`Time::HiRes::time()\*(C'\fR you seem to be getting only five decimals, notsix as promised (microseconds). Not to worry, the microseconds arethere (assuming your platform supports such granularity in the firstplace). What is going on is that the default floating point format ofPerl only outputs 15 digits. In this case that means ten digitsbefore the decimal separator and five after. To see the microsecondsyou can use either \f(CW\*(C`printf\*(C'\fR/\f(CW\*(C`sprintf\*(C'\fR with \f(CW"%.6f"\fR, or the\&\f(CW\*(C`gettimeofday()\*(C'\fR function in list context, which will give you theseconds and microseconds as two separate values..ie n .IP "sleep ( $floating_seconds )" 4.el .IP "sleep ( \f(CW$floating_seconds\fR )" 4.IX Item "sleep ( $floating_seconds )"Sleeps for the specified amount of seconds. Returns the number ofseconds actually slept (a floating point value). This function canbe imported, resulting in a nice drop-in replacement for the \f(CW\*(C`sleep\*(C'\fRprovided with perl, see the \*(L"\s-1EXAMPLES\s0\*(R" below..SpNote that the interaction between alarms and sleeps is unspecified.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -