在没有安装额外软件包的情况下获得以毫秒为单位的时间? [英] Get time in milliseconds without an installing an extra package?

查看:77
本文介绍了在没有安装额外软件包的情况下获得以毫秒为单位的时间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在不安装任何额外软件包的情况下在Perl中获得以毫秒为单位的时间?

How can I get the time in milliseconds in Perl without installing any extra package?

我正在运行Linux.

I am running Linux.

推荐答案

Time::HiRes已成为核心部分.要检查其可用性,请从命令行中检查Perl版本perl -v,或尝试将其与perl -e 'use Time::HiRes;'一起使用.

Time::HiRes has been part of the core since Perl 5.7.3. To check for its availability, check for the Perl version, perl -v, or try to use it with perl -e 'use Time::HiRes;', both from the command line.

样品用量:

use Time::HiRes qw/ time sleep /;

my $start = time;
sleep rand(10)/3;
my $end   = time;

print 'Slept for ', ( $end - $start ) , "\n";

要以Konerak的评论为基础,如果该评论不存在或无法使用,请通过反引号使用本机Linux命令:

To build on Konerak's comment, if it isn't there or it cannot be used, use native Linux commands via backticks:

sub time_since_epoch { return `date +%s.%N` }

print time_since_epoch;

这篇关于在没有安装额外软件包的情况下获得以毫秒为单位的时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆