Is there a better way to determine elapsed time in Perl?

前端 未结 4 1417
囚心锁ツ
囚心锁ツ 2021-02-01 12:47
my $start_time = [Time::HiRes::gettimeofday()];
my $diff = Time::HiRes::tv_interval($start_time);

print \"\\n\\n$diff\\n\";
4条回答
  •  故里飘歌
    2021-02-01 13:34

    This is useful for in-service timings, granularity of one second:

    At start...

    $debugtimer = time;
    $debugstr = "";
    

    ...anywhere and everywhere you like...

    kerchunk("message") # message is short description of location in code
    

    ...end of program...

    print "timings: $debugstr";
    

    ...and with your subs:

    sub kerchunk
    {
        my ($msg) = shift;
        my $pertock = time;
        my $kch = abs($debugtimer - $pertock);
        $debugstr .= "Elapsed at $msg: $kch
    \n"; }

提交回复
热议问题