=encoding euc-jp =head1 NAME =begin original Time::HiRes - High resolution alarm, sleep, gettimeofday, interval timers =end original Time::HiRes - 高精度の alarm, sleep, gettimeofday, インターバルタイマー =head1 SYNOPSIS 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); =head1 DESCRIPTION =begin original The C module implements a Perl interface to the C, C, C, C, and C/C system calls, in other words, high resolution time and timers. See the L section below and the test scripts for usage; see your system documentation for the description of the underlying C or C, C, C, and C/C calls. =end original C モジュールは C, C, C, C, C/C システムコール、言い換えれば 高精度の時刻とタイマーへの Perl インターフェースを実装します。 使い方については下記の L 節とテストスクリプトを 参照してください; 基になっている C あるいは C, C, C, そして C/C については、 システムの文書を参照してください。 =begin original If your system lacks C or an emulation of it you don't get C or the one-argument form of C. If your system lacks all of C, C, C, and C, you don't get C, C, or C. If your system lacks both C and C you don't get C or C. =end original システムに C やそのエミュレーションがなければ、 C や引数一つの形での C は使えません。 システムに C, C, C, C の どれもなければ、C, C, C は使えません。 システムに C と C の両方がなければ、 C や C は使えません。 =begin original If you try to import an unimplemented function in the C statement it will fail at compile time. =end original C 文のなかで実装されていない関数をインポートしようとすると、 コンパイル時に失敗します。 =begin original If your subsecond sleeping is implemented with C instead of C, you can mix subsecond sleeping with signals since C does not use signals. This, however, is not portable, and you should first check for the truth value of C<&Time::HiRes::d_nanosleep> to see whether you have nanosleep, and then carefully read your C C API documentation for any peculiarities. =end original 1 秒以下の sleep が C ではなく C で 実装されていれば、C はシグナルを使わないので、 1 秒以下の sleep とシグナルを混在させることができます。 しかしこれは移植性を欠きます; そしてまず最初に nanosleep を持っているのか、C<&Time::HiRes::d_nanosleep> の 値が真であるかチェックしなければなりません; それから特有なことがないか慎重に C C API 文書を 読まなければなりません。 =begin original If you are using C for something else than mixing sleeping with signals, give some thought to whether Perl is the tool you should be using for work requiring nanosecond accuracies. =end original sleep とシグナルを混在させる以外のために C を使うと、 Perl がナノ秒の正確さを要求される仕事のために使うべきツールであるか という疑問があります。 =begin original Remember that unless you are working on a I system, any clocks and timers will be imprecise, especially so if you are working in a pre-emptive multiuser system. Understand the difference between I and process time (in UNIX-like systems the sum of I and I times). Any attempt to sleep for X seconds will most probably end up sleeping B than that, but don't be surpised if you end up sleeping slightly B. =end original Remember that unless you are working on a I system, any clocks and timers will be imprecise, especially so if you are working in a pre-emptive multiuser system. Understand the difference between I and process time (in UNIX-like systems the sum of I and I times). Any attempt to sleep for X seconds will most probably end up sleeping B than that, but don't be surpised if you end up sleeping slightly B. (TBT) =begin original The following functions can be imported from this module. No functions are exported by default. =end original 以下の関数がこのモジュールからインポートできます。 デフォルトでエクスポートされる関数はありません。 =over 4 =item gettimeofday () =begin original In array context returns a two-element array with the seconds and microseconds since the epoch. In scalar context returns floating seconds like C (see below). =end original 配列コンテキストではエポックからの秒とマイクロ秒二つの要素の配列を返します。 スカラコンテキストでは、C のように秒を 浮動小数点数で返します(下記参照)。 =item usleep ( $useconds ) =begin original 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 C system call. Can also sleep for zero seconds, which often works like a I. See also C, C, and C. =end original 指定されたマイクロ秒(100 万分の 1 秒)数、sleep します。 実際に sleep したマイクロ秒数を返します。 C システムコールとは違い、1 秒以上 sleep することができます。 0 秒スリープすることもできます; しばしば I<スレッド委譲> (thread yield) のように働きます。 C, C, C もご覧ください。 =begin original Do not expect usleep() to be exact down to one microsecond. =end original usleep() が 1 マイクロ秒単位で正確と想定しないでください。 =item nanosleep ( $nanoseconds ) =begin original Sleeps for the number of nanoseconds (1e9ths of a second) specified. Returns the number of nanoseconds actually slept (accurate only to microseconds, the nearest thousand of them). Can sleep for more than one second. Can also sleep for zero seconds, which often works like a I. See also C, C, and C. =end original Sleeps for the number of nanoseconds (1e9ths of a second) specified. Returns the number of nanoseconds actually slept (accurate only to microseconds, the nearest thousand of them). Can sleep for more than one second. Can also sleep for zero seconds, which often works like a I. See also C, C, and C. (TBT) =begin original Do not expect nanosleep() to be exact down to one nanosecond. Getting even accuracy of one thousand nanoseconds is good. =end original nanosleep() がナノ秒単位で正確と想定しないでください。 1000 ナノ秒の精度でも良い方です。 =item ualarm ( $useconds [, $interval_useconds ] ) =begin original Issues a C call; the C<$interval_useconds> is optional and will be zero if unspecified, resulting in C-like behaviour. =end original C コールを発行します; C<$interval_useconds> はオプションで、 指定されなければ 0 になり、その結果は C のような動きをします。 =begin original Returns the remaining time in the alarm in microseconds, or C if an error occurred. =end original アラームの残り時間をマイクロ秒で返します; エラーが発生すると C を返します。 =begin original ualarm(0) will cancel an outstanding ualarm(). =end original ualarm(0) は未実行の ualarm() をキャンセルします。 =begin original Note that the interaction between alarms and sleeps is unspecified. =end original アラームとスリープの相互作用は未規定であることに注意してください。 =item tv_interval tv_interval ( $ref_to_gettimeofday [, $ref_to_later_gettimeofday] ) =begin original Returns the floating seconds between the two times, which should have been returned by C. If the second argument is omitted, then the current time is used. =end original 二つの時刻の時間を浮動小数点の秒数を返します。 二つの時刻は C で返されたものでなければなりません。 2 番目の引数が省略されると、現在の時刻が使われます。 =item time () =begin original Returns a floating seconds since the epoch. This function can be imported, resulting in a nice drop-in replacement for the C