Last active
August 29, 2015 13:59
-
-
Save yoshikazusawa/10648578 to your computer and use it in GitHub Desktop.
Perlでミリ秒単位の時間計測を行う(Time::HiResを利用) ref: http://qiita.com/yoshikazusawa/items/b275104ffe869fa76157
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use strict; | |
use warnings; | |
use utf8; | |
use feature qw( say ); | |
binmode(STDOUT, ":utf8"); | |
use Time::HiRes qw( usleep gettimeofday tv_interval ); | |
# 現在時刻を取得([currentsec, currentmicrosec]の構造になっている) | |
my $t0 = [gettimeofday]; | |
# 200 * 1000マイクロ秒 → 200ミリ秒のsleep | |
usleep(200 * 1000); | |
# 浮動小数点数で経過時間を取得(このサンプルだと0.20xxxx秒程) | |
my $elapsed = tv_interval($t0); | |
say int($elapsed * 1000), "ミリ秒"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
perl -MTime::HiRes=usleep,gettimeofday,tv_interval -E 'my $t0 = [gettimeofday]; usleep(200 * 1000); say int(tv_interval($t0) * 1000)' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment