Lines Matching +full:at +full:- +full:the +full:- +full:time
1 package Time::HiRes;
13 our @EXPORT_OK = qw (usleep sleep ualarm alarm gettimeofday time tv_interval
62 die "&Time::HiRes::constant not defined" if $constname eq 'constant';
67 die "$error at $file line $line.\n";
88 Carp::croak("Time::HiRes::$i(): unimplemented in this platform");
91 Time::HiRes->export_to_level(1, $this, @_);
94 XSLoader::load( 'Time::HiRes', $XS_VERSION );
102 (${$b}[0] - ${$a}[0]) + ((${$b}[1] - ${$a}[1]) / 1_000_000);
105 # Autoload methods go after =cut, and are processed by the autosplit program.
112 Time::HiRes - High resolution alarm, sleep, gettimeofday, interval timers
116 use Time::HiRes qw( usleep ualarm gettimeofday tv_interval nanosleep
133 use Time::HiRes qw ( time alarm sleep );
135 $now_fractions = time;
140 use Time::HiRes qw( setitimer getitimer );
145 use Time::HiRes qw( clock_gettime clock_getres clock_nanosleep
153 clock_nanosleep(CLOCK_REALTIME, time()*1e9 + 10e9, TIMER_ABSTIME);
157 use Time::HiRes qw( stat lstat );
163 use Time::HiRes qw( utime );
168 The C<Time::HiRes> module implements a Perl interface to the
171 resolution time and timers. See the L</EXAMPLES> section below and the
172 test scripts for usage; see your system documentation for the
173 description of the underlying C<nanosleep> or C<usleep>, C<ualarm>,
177 get C<gettimeofday()> or the one-argument form of C<tv_interval()>.
179 C<select()>, and C<poll>, you don't get C<Time::HiRes::usleep()>,
180 C<Time::HiRes::nanosleep()>, or C<Time::HiRes::sleep()>.
182 C<Time::HiRes::ualarm()> or C<Time::HiRes::alarm()>.
184 If you try to import an unimplemented function in the C<use> statement
185 it will fail at compile time.
190 and you should first check for the truth value of
191 C<&Time::HiRes::d_nanosleep> to see whether you have nanosleep, and
196 with signals, give some thought to whether Perl is the tool you should
201 in a pre-emptive multiuser system. Understand the difference between
202 I<wallclock time> and process time (in UNIX-like systems the sum of
207 The following functions can be imported from this module.
214 In array context returns a two-element array with the seconds and
215 microseconds since the epoch. In scalar context returns floating
216 seconds like C<Time::HiRes::time()> (see below).
220 Sleeps for the number of microseconds (millionths of a second)
221 specified. Returns the number of microseconds actually slept.
222 Can sleep for more than one second, unlike the C<usleep> system call.
224 See also L<C<Time::HiRes::sleep()>|/sleep ( $floating_seconds )>, and
231 Sleeps for the number of nanoseconds (1e9ths of a second) specified.
232 Returns the number of nanoseconds actually slept (accurate only to
233 microseconds, the nearest thousand of them). Can sleep for more than
236 L<C<Time::HiRes::sleep()>|/sleep ( $floating_seconds )>,
237 L<C<Time::HiRes::usleep()>|/usleep ( $useconds )>, and
245 Issues a C<ualarm> call; the C<$interval_useconds> is optional and
246 will be zero if unspecified, resulting in C<alarm>-like behaviour.
248 Returns the remaining time in the alarm in microseconds, or C<undef>
253 Note that the interaction between alarms and sleeps is unspecified.
259 Returns the floating seconds between the two times, which should have
260 been returned by C<gettimeofday()>. If the second argument is omitted,
261 then the current time is used.
263 =item time ()
265 Returns a floating seconds since the epoch. This function can be
266 imported, resulting in a nice drop-in replacement for the C<time>
267 provided with core Perl; see the L</EXAMPLES> below.
270 or more than the core C<time()>, depending on whether your platform
271 rounds the higher resolution timer values up, down, or to the nearest second
272 to get the core C<time()>, but naturally the difference should be never
276 B<NOTE 2>: Since Sunday, September 9th, 2001 at 01:46:40 AM GMT, when
277 the C<time()> seconds since epoch rolled over to 1_000_000_000, the
278 default floating point format of Perl and the seconds since epoch have
279 conspired to produce an apparent bug: if you print the value of
280 C<Time::HiRes::time()> you seem to be getting only five decimals, not
281 six as promised (microseconds). Not to worry, the microseconds are
282 there (assuming your platform supports such granularity in the first
283 place). What is going on is that the default floating point format of
285 before the decimal separator and five after. To see the microseconds
286 you can use either C<printf>/C<sprintf> with C<"%.6f">, or the
287 C<gettimeofday()> function in list context, which will give you the
292 Sleeps for the specified amount of seconds. Returns the number of
294 be imported, resulting in a nice drop-in replacement for the C<sleep>
295 provided with perl, see the L</EXAMPLES> below.
297 Note that the interaction between alarms and sleeps is unspecified.
301 The C<SIGALRM> signal is sent after the specified number of seconds.
303 The C<$interval_floating_seconds> argument is optional and will be
304 zero if unspecified, resulting in C<alarm()>-like behaviour. This
305 function can be imported, resulting in a nice drop-in replacement for
306 the C<alarm> provided with perl, see the L</EXAMPLES> below.
308 Returns the remaining time in the alarm in seconds, or C<undef>
314 take the sum of the times specified for the C<alarm()> and the
315 C<select()>, not just the time of the C<alarm()>.
317 Note that the interaction between alarms and sleeps is unspecified.
321 Start up an interval timer: after a certain time, a signal ($which) arrives,
322 and more signals may keep arriving at certain intervals. To disable
323 an "itimer", use C<$floating_seconds> of zero. If the
324 C<$interval_floating_seconds> is set to zero (or unspecified), the
325 timer is disabled B<after> the next delivered signal.
328 and C<usleep()>. In standard-speak the "interaction is unspecified",
331 In scalar context, the remaining time in the timer is returned.
333 In list context, both the remaining time and the interval are returned.
335 There are usually three or four interval timers (signals) available: the
338 UNIX platforms usually have the first three, but only Solaris seems to
342 C<ITIMER_REAL> results in C<alarm()>-like behaviour. Time is counted in
343 I<real time>; that is, wallclock time. C<SIGALRM> is delivered when
344 the timer expires.
346 C<ITIMER_VIRTUAL> counts time in (process) I<virtual time>; that is,
347 only when the process is running. In multiprocessor/user/CPU systems
348 this may be more or less than real or wallclock time. (This time is
349 also known as the I<user time>.) C<SIGVTALRM> is delivered when the
352 C<ITIMER_PROF> counts time when either the process virtual time or when
353 the operating system is running on behalf of the process (such as I/O).
354 (This time is also known as the I<system time>.) (The sum of user
355 time and system time is known as the I<CPU time>.) C<SIGPROF> is
356 delivered when the timer expires. C<SIGPROF> can interrupt system calls.
358 The semantics of interval timers for multithreaded programs are
359 system-specific, and some systems may support additional interval
360 timers. For example, it is unspecified which thread gets the signals.
365 Return the remaining time in the interval timer specified by C<$which>.
367 In scalar context, the remaining time is returned.
369 In list context, both the remaining time and the interval are returned.
370 The interval is always what you put in using C<setitimer()>.
374 Return as seconds the current value of the POSIX high resolution timer
376 resolution timers are supposed to support at least the C<$which> value
377 of C<CLOCK_REALTIME>, which is supposed to return results close to the
378 results of C<gettimeofday>, or the number of seconds since 00:00:00:00
379 January 1, 1970 Greenwich Mean Time (GMT). Do not assume that
382 C<CLOCK_MONOTONIC>, which guarantees a monotonically increasing time
383 value (unlike time() or gettimeofday(), which can be adjusted).
388 Return as seconds the resolution of the POSIX high resolution timer
390 resolution timers are supposed to support at least the C<$which> value
393 B<NOTE>: the resolution returned may be highly optimistic. Even if
394 the resolution is high (a small number), all it means is that you'll
395 be able to specify the arguments to clock_gettime() and clock_nanosleep()
396 with that resolution. The system might not actually be able to measure
397 events at that resolution, and the various overheads and the overall system
402 Sleeps for the number of nanoseconds (1e9ths of a second) specified.
403 Returns the number of nanoseconds actually slept. The $which is the
404 "clock id", as with clock_gettime() and clock_getres(). The flags
406 explicitly) which means that C<$nanoseconds> is not a time interval
407 (as is the default) but instead an absolute time. Can sleep for more
410 L<C<Time::HiRes::sleep()>|/sleep ( $floating_seconds )>,
411 L<C<Time::HiRes::usleep()>|/usleep ( $useconds )>, and
412 L<C<Time::HiRes::nanosleep()>|/nanosleep ( $nanoseconds )>.
419 Return as seconds the I<process time> (user + system time) spent by
420 the process since the first call to clock() (the definition is B<not>
421 "since the start of the process", though if you are lucky these times
422 may be quite close to each other, depending on the system). What this
423 means is that you probably need to store the result of your first call
424 to clock(), and subtract that value from the following results of clock().
426 The time returned also includes the process times of the terminated
428 somewhat like the second value returned by the times() of core Perl,
430 compatibility limitations the returned value may wrap around at about
431 2147 seconds or at about 36 minutes.
446 but with the access/modify/change file timestamps
447 in subsecond resolution, if the operating system and the filesystem
448 both support such timestamps. To override the standard stat():
450 use Time::HiRes qw(stat);
452 Test for the value of &Time::HiRes::d_hires_stat to find out whether
453 the operating system supports subsecond file timestamps: a value
455 ways to find out whether the filesystem supports such timestamps.
459 A zero return value of &Time::HiRes::d_hires_stat means that
460 Time::HiRes::stat is a no-op passthrough for CORE::stat()
462 and therefore the timestamps will stay integers. The same
463 thing will happen if the filesystem does not do subsecond timestamps,
464 even if the &Time::HiRes::d_hires_stat is non-zero.
467 resolution. Also note that the modify/access timestamps might have
469 if the operations are
476 the access time stamp from t2 need not be greater-than the modify
477 time stamp from t1: it may be equal or I<less>.
482 but with the ability to set the access/modify file timestamps
483 in subsecond resolution, if the operating system and the filesystem,
484 and the mount options of the filesystem, all support such timestamps.
486 To override the standard utime():
488 use Time::HiRes qw(utime);
490 Test for the value of &Time::HiRes::d_hires_utime to find out whether
491 the operating system supports setting subsecond file timestamps.
493 As with CORE::utime(), passing undef as both the atime and mtime will
494 call the syscall with a NULL argument.
496 The actual achievable subsecond resolution depends on the combination
497 of the operating system and the filesystem.
499 Modifying the timestamps may not be possible at all: for example, the
500 C<noatime> filesystem mount option may prohibit you from changing the
501 access time timestamp.
503 Returns the number of files successfully changed.
509 use Time::HiRes qw(usleep ualarm gettimeofday tv_interval);
519 # get seconds and microseconds since the epoch
522 # measure elapsed time
534 # replacements for time, alarm and sleep that know about
537 use Time::HiRes;
538 $now_fractions = Time::HiRes::time;
539 Time::HiRes::sleep (2.5);
540 Time::HiRes::alarm (10.6666666);
542 use Time::HiRes qw ( time alarm sleep );
543 $now_fractions = time;
547 # Arm an interval timer to go off first at 10 seconds and
548 # after that every 2.5 seconds, in process virtual time
550 use Time::HiRes qw ( setitimer ITIMER_VIRTUAL time );
552 $SIG{VTALRM} = sub { print time, "\n" };
555 use Time::HiRes qw( clock_gettime clock_getres CLOCK_REALTIME );
556 # Read the POSIX high resolution timer.
561 use Time::HiRes qw( clock_nanosleep TIMER_ABSTIME );
565 use Time::HiRes qw( clock );
569 my $clockd = $clock1 - $clock0;
571 use Time::HiRes qw( stat );
576 In addition to the perl API described above, a C API is available for
577 extension writers. The following C functions are available in the
581 --------------- ----------------------
582 Time::NVtime NV (*)()
583 Time::U2time void (*)(pTHX_ UV ret[2])
586 but with different representations. The names C<NVtime> and C<U2time>
588 (C<gettimeofday> is Unix-centric, though some platforms like Win32 and
593 NV (*myNVtime)(); /* Returns -1 on failure. */
594 SV **svp = hv_fetchs(PL_modglobal, "Time::NVtime", 0);
595 if (!svp) croak("Time::HiRes is required");
596 if (!SvIOK(*svp)) croak("Time::NVtime isn't a function pointer");
598 printf("The current time is: %" NVff "\n", (*myNVtime)());
608 =head2 negative time not invented yet
610 You tried to use a negative time argument.
614 Something went horribly wrong-- the number of microseconds that cannot
628 Notice that the core C<time()> maybe rounding rather than truncating.
629 What this means is that the core C<time()> may be reporting the time
630 as one second later than C<gettimeofday()> and C<Time::HiRes::time()>.
632 Adjusting the system clock (either manually or by services like ntp)
634 a monotonously increasing time (note that all platforms do not adjust
635 time as gracefully as UNIX ntp does). For example in Win32 (and derived
636 platforms like Cygwin and MinGW) the Time::HiRes::time() may temporarily
637 drift off from the system clock (and the original time()) by up to 0.5
638 seconds. Time::HiRes will notice this eventually and recalibrate.
639 Note that since Time::HiRes 1.77 the clock_gettime(CLOCK_MONOTONIC)
643 have the interval timer APIs but not the functionality.
645 In pre-Sierra macOS (pre-10.12, OS X) clock_getres(), clock_gettime()
646 and clock_nanosleep() are emulated using the Mach timers; as a side
647 effect of being emulated the CLOCK_REALTIME and CLOCK_MONOTONIC are
648 the same timer.
650 gnukfreebsd seems to have non-functional futimens() and utimensat()
651 (at least as of 10.1): therefore the hires utime() does not work.
655 Perl modules L<BSD::Resource>, L<Time::TAI64>.
671 Copyright (c) 1996-2002 Douglas E. Wegscheid. All rights reserved.
679 it under the same terms as Perl itself.