Q about Coro file::find
Zsbán Ambrus
ambrus at math.bme.hu
Thu Feb 2 12:10:24 CET 2012
On 2/1/12, Aleksandar Lazic <al-anyevent at none.at> wrote:
> OT: Is there a better way to print the elapsed time then this?
> POSIX::strftime("%T",Time::HiRes::time-$tgesammt ,0,0,0,0,0)
That does work, but as you're asking about it, yes, it could be
improved if you're pedantic.
The first problem is that if your time duration is more than one day,
this "%T" format will silently print the value only modulo one day.
If this is a problem, one solution would be something like this (where
$dt is the number of seconds elapsed):
use Date::Manip;
print Delta_Format((0+$dt) . " sec", 0, "%02hyh:%02mmm:%02sss\n");
The second is that in theory you're supposed to pass only normalized
tm data to strftime, because that function is free to assume the
seconds part really only contains seconds, so I'd rather use the
gmtime function to make the tm structure from the seconds for you, eg.
POSIX::strftime("%T", gmtime($dt))
The third is that if you want to measure elapsed time, it could be
better to call Time::HiRes::clock_gettime(Time::HiRes::CLOCK_MONOTONIC())
instead of Time::HiRes::time -- though this doesn't usually make a
difference. Obviously you have to use the same call to get the time
at the beginning and at the end of the process.
Ambrus
More information about the anyevent
mailing list