The Time::HiRes module implements a Perl interface to the usleep, ualarm, and gettimeofday system calls. See the EXAMPLES section below and the test scripts for usage; see your system documentation for the description of the underlying gettimeofday, usleep, and ualarm calls.

If your system lacks gettimeofday(2) you don't get gettimeofday() or the one-arg form of tv_interval(). If you don't have usleep(3) or select(2) you don't get usleep() or sleep(). If your system don't have ualarm(3) or setitimer(2) you don't get ualarm() or alarm(). If you try to import an unimplemented function in the use statement it will fail at compile time.

The following functions can be imported from this module. No functions are exported by default.

Converts $floating_seconds to microseconds and issues a usleep for the result. This function can be imported, resulting in a nice drop-in replacement for the sleep provided with perl, see the EXAMPLES below.

Converts $floating_seconds and $interval_floating_seconds and issues a ualarm for the results. The $interval_floating_seconds argument is optional and will be 0 if unspecified, resulting in alarm-like behaviour. This function can be imported, resulting in a nice drop-in replacement for the alarm provided with perl, see the EXAMPLES below.

Start up an interval timer: after a certain time, a signal is arrives, and more may keep arriving at certain intervals. To disable a timer, use time of zero. If interval is set to zero (or unspecified), the timer is disabled after the next delivered signal.

Use of interval timers may interfere with alarm(), sleep(), and usleep(). In standard-speak the "interaction is unspecified", which means that anything may happen: it may work, it may not.

In scalar context, the remaining time in the timer is returned.

In list context, both the remaining time and the interval are returned.

There are three interval timers: the $which can be ITIMER_REAL, ITIMER_VIRTUAL, or ITIMER_PROF.

ITIMER_REAL results in alarm()-like behavior. Time is counted in real time, that is, wallclock time. SIGALRM is delivered when the timer expires.

ITIMER_VIRTUAL counts time in (process) virtual time, that is, only when the process is running. In multiprocessing/user/CPU systems this may be much less than real time. (This time is also known as the user time.) SIGVTALRM is delivered when the timer expires.

ITIMER_PROF 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 system time.) (Collectively these times are also known as the CPU time.) SIGPROF is delivered when the timer expires. SIGPROF can interrupt system calls.

The semantics of interval timers for multithreaded programs are system-specific, and some systems may support additional interval timers. See your setitimer() documentation.

Both functions return equivalent information (like gettimeofday) but with different representations. The names NVtime and U2time were selected mainly because they are operating system independent. (gettimeofday is Un*x-centric.)