JJ *_*Liu 11 linux perl time package milliseconds
如何在不安装任何额外软件包的情况下在Perl中获取毫秒的时间?
我正在运行Linux.
Zai*_*aid 22
Time::HiRes自Perl 5.7.3以来一直是核心的一部分.要检查其可用性,请从命令行检查Perl版本perl -v,或尝试使用它perl -e 'use Time::HiRes;'.
样品用法:
use Time::HiRes qw/ time sleep /;
my $start = time;
sleep rand(10)/3;
my $end = time;
print 'Slept for ', ( $end - $start ) , "\n";
Run Code Online (Sandbox Code Playgroud)
要建立Konerak的注释,如果它不存在或无法使用,请通过反引号使用本机Linux命令:
sub time_since_epoch { return `date +%s.%N` }
print time_since_epoch;
Run Code Online (Sandbox Code Playgroud)