perlfaq nodetype
faq_monk
<P>
In general, you may not be able to. The Time::HiRes module (available from
<FONT SIZE=-1>CPAN)</FONT> provides this functionality for some systems.
<P>
In general, you may not be able to. But if your system supports both the
<CODE>syscall()</CODE> function in Perl as well as a system call like
<CODE>gettimeofday(2),</CODE> then you may be able to do something like this:
<P>
<PRE> require 'sys/syscall.ph';
</PRE>
<P>
<PRE> $TIMEVAL_T = "LL";
</PRE>
<P>
<PRE> $done = $start = pack($TIMEVAL_T, ());
</PRE>
<P>
<PRE> syscall( &SYS_gettimeofday, $start, 0)) != -1
or die "gettimeofday: $!";
</PRE>
<P>
<PRE> ##########################
# DO YOUR OPERATION HERE #
##########################
</PRE>
<P>
<PRE> syscall( &SYS_gettimeofday, $done, 0) != -1
or die "gettimeofday: $!";
</PRE>
<P>
<PRE> @start = unpack($TIMEVAL_T, $start);
@done = unpack($TIMEVAL_T, $done);
</PRE>
<P>
<PRE> # fix microseconds
for ($done[1], $start[1]) { $_ /= 1_000_000 }
</PRE>
<P>
<PRE> $delta_time = sprintf "%.4f", ($done[0] + $done[1] )
-
($start[0] + $start[1] );
</PRE>
<P>