hires.html
来自「perl教程」· HTML 代码 · 共 546 行 · 第 1/3 页
HTML
546 行
<dt><strong><a name="item_tv_interval">tv_interval</a></strong>
<dd>
<p>tv_interval ( $ref_to_gettimeofday [, $ref_to_later_gettimeofday] )</p>
</dd>
<dd>
<p>Returns the floating seconds between the two times, which should have
been returned by <a href="#item_gettimeofday"><code>gettimeofday()</code></a>. If the second argument is omitted,
then the current time is used.</p>
</dd>
</li>
<dt><strong><a name="item_time">time ()</a></strong>
<dd>
<p>Returns a floating seconds since the epoch. This function can be
imported, resulting in a nice drop-in replacement for the <a href="#item_time"><code>time</code></a>
provided with core Perl; see the <a href="#examples">EXAMPLES</a> below.</p>
</dd>
<dd>
<p><strong>NOTE 1</strong>: This higher resolution timer can return values either less
or more than the core <a href="#item_time"><code>time()</code></a>, depending on whether your platform
rounds the higher resolution timer values up, down, or to the nearest second
to get the core <a href="#item_time"><code>time()</code></a>, but naturally the difference should be never
more than half a second. See also <a href="#item_clock_getres">clock_getres</a>, if available
in your system.</p>
</dd>
<dd>
<p><strong>NOTE 2</strong>: Since Sunday, September 9th, 2001 at 01:46:40 AM GMT, when
the <a href="#item_time"><code>time()</code></a> seconds since epoch rolled over to 1_000_000_000, the
default floating point format of Perl and the seconds since epoch have
conspired to produce an apparent bug: if you print the value of
<a href="#item_time"><code>Time::HiRes::time()</code></a> you seem to be getting only five decimals, not
six as promised (microseconds). Not to worry, the microseconds are
there (assuming your platform supports such granularity in the first
place). What is going on is that the default floating point format of
Perl only outputs 15 digits. In this case that means ten digits
before the decimal separator and five after. To see the microseconds
you can use either <a href="../../lib/Pod/perlfunc.html#item_printf"><code>printf</code></a>/<a href="../../lib/Pod/perlfunc.html#item_sprintf"><code>sprintf</code></a> with <code>"%.6f"</code>, or the
<a href="#item_gettimeofday"><code>gettimeofday()</code></a> function in list context, which will give you the
seconds and microseconds as two separate values.</p>
</dd>
</li>
<dt><strong><a name="item_sleep">sleep ( $floating_seconds )</a></strong>
<dd>
<p>Sleeps for the specified amount of seconds. Returns the number of
seconds actually slept (a floating point value). This function can
be imported, resulting in a nice drop-in replacement for the <a href="#item_sleep"><code>sleep</code></a>
provided with perl, see the <a href="#examples">EXAMPLES</a> below.</p>
</dd>
<dd>
<p>Note that the interaction between alarms and sleeps is unspecified.</p>
</dd>
</li>
<dt><strong><a name="item_alarm">alarm ( $floating_seconds [, $interval_floating_seconds ] )</a></strong>
<dd>
<p>The <code>SIGALRM</code> signal is sent after the specified number of seconds.
Implemented using <a href="#item_ualarm"><code>ualarm()</code></a>. The <code>$interval_floating_seconds</code> argument
is optional and will be zero if unspecified, resulting in <a href="#item_alarm"><code>alarm()</code></a>-like
behaviour. This function can be imported, resulting in a nice drop-in
replacement for the <a href="#item_alarm"><code>alarm</code></a> provided with perl, see the <a href="#examples">EXAMPLES</a> below.</p>
</dd>
<dd>
<p><strong>NOTE 1</strong>: With some combinations of operating systems and Perl
releases <code>SIGALRM</code> restarts <a href="../../lib/Pod/perlfunc.html#item_select"><code>select()</code></a>, instead of interrupting it.
This means that an <a href="#item_alarm"><code>alarm()</code></a> followed by a <a href="../../lib/Pod/perlfunc.html#item_select"><code>select()</code></a> may together
take the sum of the times specified for the the <a href="#item_alarm"><code>alarm()</code></a> and the
<a href="../../lib/Pod/perlfunc.html#item_select"><code>select()</code></a>, not just the time of the <a href="#item_alarm"><code>alarm()</code></a>.</p>
</dd>
<dd>
<p>Note that the interaction between alarms and sleeps is unspecified.</p>
</dd>
</li>
<dt><strong><a name="item_setitimer">setitimer ( $which, $floating_seconds [, $interval_floating_seconds ] )</a></strong>
<dd>
<p>Start up an interval timer: after a certain time, a signal arrives,
and more signals may keep arriving at certain intervals. To disable
an "itimer", use <code>$floating_seconds</code> of zero. If the
<code>$interval_floating_seconds</code> is set to zero (or unspecified), the
timer is disabled <strong>after</strong> the next delivered signal.</p>
</dd>
<dd>
<p>Use of interval timers may interfere with <a href="#item_alarm"><code>alarm()</code></a>, <a href="#item_sleep"><code>sleep()</code></a>,
and <a href="#item_usleep"><code>usleep()</code></a>. In standard-speak the "interaction is unspecified",
which means that <em>anything</em> may happen: it may work, it may not.</p>
</dd>
<dd>
<p>In scalar context, the remaining time in the timer is returned.</p>
</dd>
<dd>
<p>In list context, both the remaining time and the interval are returned.</p>
</dd>
<dd>
<p>There are usually three or four interval timers available: the
<code>$which</code> can be <code>ITIMER_REAL</code>, <code>ITIMER_VIRTUAL</code>, <code>ITIMER_PROF</code>, or
<code>ITIMER_REALPROF</code>. Note that which ones are available depends: true
UNIX platforms usually have the first three, but (for example) Win32
and Cygwin have only <code>ITIMER_REAL</code>, and only Solaris seems to have
<code>ITIMER_REALPROF</code> (which is used to profile multithreaded programs).</p>
</dd>
<dd>
<p><code>ITIMER_REAL</code> results in <a href="#item_alarm"><code>alarm()</code></a>-like behaviour. Time is counted in
<em>real time</em>; that is, wallclock time. <code>SIGALRM</code> is delivered when
the timer expires.</p>
</dd>
<dd>
<p><code>ITIMER_VIRTUAL</code> counts time in (process) <em>virtual time</em>; that is,
only when the process is running. In multiprocessor/user/CPU systems
this may be more or less than real or wallclock time. (This time is
also known as the <em>user time</em>.) <code>SIGVTALRM</code> is delivered when the
timer expires.</p>
</dd>
<dd>
<p><code>ITIMER_PROF</code> counts time when either the process virtual time or when
the operating system is running on behalf of the process (such as I/O).
(This time is also known as the <em>system time</em>.) (The sum of user
time and system time is known as the <em>CPU time</em>.) <code>SIGPROF</code> is
delivered when the timer expires. <code>SIGPROF</code> can interrupt system calls.</p>
</dd>
<dd>
<p>The semantics of interval timers for multithreaded programs are
system-specific, and some systems may support additional interval
timers. See your <a href="#item_setitimer"><code>setitimer()</code></a> documentation.</p>
</dd>
</li>
<dt><strong><a name="item_getitimer">getitimer ( $which )</a></strong>
<dd>
<p>Return the remaining time in the interval timer specified by <code>$which</code>.</p>
</dd>
<dd>
<p>In scalar context, the remaining time is returned.</p>
</dd>
<dd>
<p>In list context, both the remaining time and the interval are returned.
The interval is always what you put in using <a href="#item_setitimer"><code>setitimer()</code></a>.</p>
</dd>
</li>
<dt><strong><a name="item_clock_gettime">clock_gettime ( $which )</a></strong>
<dd>
<p>Return as seconds the current value of the POSIX high resolution timer
specified by <code>$which</code>. All implementations that support POSIX high
resolution timers are supposed to support at least the <code>$which</code> value
of <code>CLOCK_REALTIME</code>, which is supposed to return results close to the
results of <a href="#item_gettimeofday"><code>gettimeofday</code></a>, or the number of seconds since 00:00:00:00
January 1, 1970 Greenwich Mean Time (GMT). Do not assume that
CLOCK_REALTIME is zero, it might be one, or something else.
Another potentially useful (but not available everywhere) value is
<code>CLOCK_MONOTONIC</code>, which guarantees a monotonically increasing time
value (unlike time(), which can be adjusted). See your system
documentation for other possibly supported values.</p>
</dd>
</li>
<dt><strong><a name="item_clock_getres">clock_getres ( $which )</a></strong>
<dd>
<p>Return as seconds the resolution of the POSIX high resolution timer
specified by <code>$which</code>. All implementations that support POSIX high
resolution timers are supposed to support at least the <code>$which</code> value
of <code>CLOCK_REALTIME</code>, see <a href="#item_clock_gettime">clock_gettime</a>.</p>
</dd>
</li>
<dt><strong><a name="item_clock_nanosleep">clock_nanosleep ( $which, $seconds, $flags = 0)</a></strong>
<dd>
<p>Sleeps for the number of seconds (1e9ths of a second) specified.
Returns the number of seconds actually slept. The $which is the
"clock id", as with <a href="#item_clock_gettime"><code>clock_gettime()</code></a> and clock_getres(). The flags
default to zero but <code>TIMER_ABSTIME</code> can specified (must be exported
explicitly) which means that <code>$nanoseconds</code> is not a time interval
(as is the default) but instead an absolute time. Can sleep for more
than one second. Can also sleep for zero seconds, which often works
like a <em>thread yield</em>. See also <a href="#item_sleep"><code>Time::HiRes::sleep()</code></a>,
<a href="#item_usleep"><code>Time::HiRes::usleep()</code></a>, and <a href="#item_nanosleep"><code>Time::HiRes::nanosleep()</code></a>.</p>
</dd>
<dd>
<p>Do not expect <a href="#item_clock_nanosleep"><code>clock_nanosleep()</code></a> to be exact down to one nanosecond.
Getting even accuracy of one thousand nanoseconds is good.</p>
</dd>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?