Time::HiResでの礼儀正しい経過時間計測法

まあマニュアル通りなんですが。
use Time::HiRes (qw/time gettimeofday tv_interval/);
まちがい
$time = time; # do something $elapse = time - $time;
正しい
$time = [ gettimeofday ]; # do something $elapse = tv_interval $time; # 2つのポイント間を計りたい場合は第二引数にも参照を渡す
マニュアルより。
time - NOTE 1: This higher resolution timer can return values either less or more than the core time(), depending on whether your platform rounds the higher resolution timer values up, down, or to the nearest second to get the core time(), but naturally the difference should be never more than half a second. See also "clock_getres", if available in your system. 注意1: タイマーは多かれ少なかれコアのtime()に比べれば解像度の高い時刻を返すことができるが、それは プラットフォームに環境依存し、解像度は変動する。あるいはCコアのtime()と同じ値に近似することさえある。 しかし普通は0.5秒を超える誤差は起こらない。clock_getresを見よ
逆に読むと、なんと最大で0.5秒の誤差があり、time()と出力が変わらないことすらあるという。そもそもあまり便利な関数ではないらしい。 ここはやはりgettimeofdayを使ってマイクロセカンド秒を取得し、tv_interval関数で差分を取るのがより正確な経過時間を知る方法だ。 そもそも帰ってくるのは浮動小数点数なので、コンマ何秒の計測をする場合には仮にtime()が正確でもより正確な経過時間が期待できる(*)
ちなみにダメな方の方法だと、0.数秒かかる処理が0.0秒ジャストと計測されてしまうことも珍しくない(実体験)。
(*)浮動小数点数はその性質上正確な数値を表せる桁数が限られており、その上UNIXタイムは整数部だけで10桁を消費する。 このためUNIXタイムを浮動小数点数で表すと小数点以下が不正確になることは充分にありえることだ。
2011/12/09 - 21:03:52 -
Read was interesting, stay in touch…
[…]please visit the sites we follow, including this one, as it represents our picks from the web[…]…
2011/12/09 - 21:32:27 -
Check this out
[…] that is the end of this article. Here you’ll find some sites that we think you’ll appreciate, just click the links over[…]…
2011/12/09 - 21:43:42 -
The best website……
[…]here are some links to sites that we link to because we think they are worth visiting[…]……
2011/12/10 - 02:30:17 -
far east plaza directory
[…]It was as if Hendra virus awoke[…]
2011/12/10 - 03:19:04 -
far eastern economic review malaysia
[…]physicists working at Trinity College in Dublin, Ireland[…]
2011/12/10 - 03:42:03 -
Tumblr article
I saw someone writing about this on Tumblr and it linked to
2011/12/10 - 04:47:27 -
far east organisation china
[…]physicists working at Trinity College in Dublin, Ireland[…]
2011/12/10 - 12:58:39 -
Recommeneded websites
[…]Here are some of the sites we recommend for our visitors[…]…
2011/12/10 - 19:57:41 -
Recommeneded websites…
[…]Here are some of the sites we recommend for our visitors[…]……
2011/12/10 - 22:16:14 -
Online Articleâ?¦
[…]The information mentioned in the article are some of the best available […]…
2011/12/10 - 23:15:57 -
Digg
While checking out DIGG today I found this
2011/12/11 - 01:16:59 -
Related…
[…]just beneath, are numerous totally not related sites to ours, however, they are surely worth going over[…]…
2011/12/11 - 02:53:48 -
Awesome website
[…]the time to read or visit the content or sites we have linked to below the[…]…
2011/12/11 - 03:45:55 -
Recent Blogroll Additions…
[…]usually posts some very interesting stuff like this. If you’re new to this site[…]…
2011/12/11 - 06:02:07 -
Blogs ou should be reading
[…]Here is a Great Blog You Might Find Interesting that we Encourage You[…]…
2011/12/11 - 14:44:16 -
abdicate
ugg classic tall boots navyMoncler jackets are modish,pandora packages well-cut,kids ugg bailey button boots grey lightweight and extremely warm
2011/12/11 - 18:12:28 -
Check this out
[…] that is the end of this article. Here you’ll find some sites that we think you’ll appreciate, just click the links over[…]…
2011/12/11 - 18:46:37 -
Links…
[…]Sites of interest we have a link to[…]……
2011/12/11 - 20:30:04 -
modern politics government 7th edition
[…]then in May, something happened[…]
2011/12/11 - 23:07:39 -
News info
I was reading the news and I saw this really cool topic
2011/12/12 - 00:51:52 -
modern politics questions
[…]health officials concluded in 2004 that more than three-quarters of[…]
2011/12/12 - 03:25:42 -
Superb website
[…]always a big fan of linking to bloggers that I love but don’t get a lot of link love from[…]…
2011/12/12 - 22:02:03 -
Read was interesting, stay in touch…
[…]please visit the sites we follow, including this one, as it represents our picks from the web[…]…
2011/12/13 - 00:05:37 -
Websites we think you should visit
[…]although websites we backlink to below are considerably not related to ours, we feel they are actually worth a go through, so have a look[…]…
2011/12/14 - 00:04:41 -
Sources…
[…]check below, are some totally unrelated websites to ours, however, they are most trustworthy sources that we use[…]……
2011/12/14 - 00:58:37 -
Superb website
[…]always a big fan of linking to bloggers that I love but don’t get a lot of link love from[…]…
2011/12/14 - 03:32:32 -
far east movement lyrics omg
[…]alphabet soup of deadly and economically damaging zoonotic […]
2011/12/14 - 04:03:45 -
Visitor recommendations
[…]one of our visitors recently recommended the following website[…]…
2011/12/14 - 20:29:36 -
Recommeneded websites
[…]Here are some of the sites we recommend for our visitors[…]…
2011/12/14 - 21:50:14 -
Websites you should visit
[…]below you’ll find the link to some sites that we think you should visit[…]…
2011/12/15 - 03:14:23 -
far east florist thomson
[…]also called flying foxes, spread the disease to horses[…]
2011/12/15 - 17:40:10 -
far east nanny
[…]floods are expected more frequently with climate change ? so[…]
2011/12/16 - 01:08:33 -
Sites we Like…
[…] Every once in a while we choose blogs that we read. Listed below are the latest sites that we choose […]…
2011/12/16 - 05:44:31 -
Websites we think you should visit
[…]although websites we backlink to below are considerably not related to ours, we feel they are actually worth a go through, so have a look[…]…
2011/12/16 - 06:15:31 -
far east movement like a g6
[…]perfect here means the lowest-energy configuration[…]
2011/12/16 - 08:32:07 -
Websites we think you should visit
[…]although websites we backlink to below are considerably not related to ours, we feel they are actually worth a go through, so have a look[…]…
2012/01/07 - 07:11:26 -
[spam trap]ここは編集しないでください。コメントは下のボックスにお願いします(Please leave here as is. To comment, use textarea below.)