Now if you only need to the seccond accuracy you can use this:
$start=time;
## do something you want to measure.
$end=time;
$elapsed=$end-$start;
print "$elapsed seconds elapsed\n";
But, if you need better accuracy, you can use this:
My friend found this, it lets me mesure an event in fractions of a second:
require 'sys/syscall.ph';
$TIMEVAL_T = "LL";
$done = $start = pack($TIMEVAL_T, ());
syscall( &SYS_gettimeofday, $start, 0) != -1 or die "gettimeofday: $!";
### do something here you want to measure
syscall( &SYS_gettimeofday, $done, 0) != -1
or die "gettimeofday: $!";
@start = unpack($TIMEVAL_T, $start);
@done = unpack($TIMEVAL_T, $done);
# fix microseconds
for ($done[1], $start[1]) { $_ /= 1_000_000 }
$delta_time = sprintf "%.4f", ($done[0] + $done[1] )
-
($start[0] + $start[1] );
I don't know how accurate it is. I was just looking for fractions of a second 0.1 .. 0.9 .. but it returns 4 digiits , but that comes from the sprintf command, I don't know if that means it's only that accurate. (it might not even be that good )
Now this didn't work the first time for me (rhat 9.0) . perl died with a missing module,not syscal but rather asm:unistd.ph , my friend had found this file on his newer configuration, and on a lark I put his copy in what I figured should be the correct location /usr/lib/perl5/5.8.0/i386-linux-thread-multi/asm (I had to create 'asm') and to my suprise, it worked.
I have saved that copy of unistd.ph here
|