By way of a method (excessively detailed which is also guilty of re-inventing a wheel) of getting a (low res, W32) execution time:
#!C:\perl\bin\perl.exe -lw my $starttime = localtime(); my $starthms = $starttime; $starthms =~ /[A-Z]+\s[A-Z]+\s+\d+\s+(\d{2}:\d{2}:\d{2}).*/i; $starthms = $1; print $starthms; if ( $starthms =~ /(\d+):(\d+):(\d+)/ ) { my $hours = $1; my $minutes = $2; my $seconds = $3; our $startsecs = ($hours*60*60) + ($minutes*60) + $seconds; } sleep 2; # insert your code to be timed my $endtime = localtime(); my $endtimehms = $endtime; $endtimehms =~ /[A-Z]+\s[A-Z]+\s+\d+\s+(\d{2}:\d{2}:\d{2}).*/i; $endpart = $1; if ( $endpart =~ /(\d+):(\d+):(\d+)/ ) { local $hours = $1; local $minutes = $2; local $seconds = $3; our $endtimesecs = ($hours*60*60) + ($minutes*60) + $seconds; } print "\$endpart: $endpart and Runduration: " . ($endtimesecs - $start +secs) . " seconds"; print "=======================\n"; use POSIX; print "starttime, \$^T without POSIX: $^T"; print "Start time, , \$^T with POSIX: " . POSIX::strftime "%H:%M:%S", + localtime($^T); print "\t2nd POSIX, \$^T: " . POSIX::strftime "%H:%M:%S", localtime($^ +T); print "\t3rd POSIX, current time: " . POSIX::strftime "%H:%M:%S", loca +ltime(); print "local_time(): " . localtime();
Upon execution,
11:10:11 $endpart: 11:10:13 and Runduration: 2 seconds ======================= starttime, $^T without POSIX: 1233763810 Start time, , $^T with POSIX: 11:10:10 2nd POSIX, $^T: 11:10:10 3rd POSIX, current time: 11:10:13 local_time(): Wed Feb 4 11:10:13 2009 POSIX localtime: Wed Feb 11:10:13 2009 ...and after sleeping another second, POSIX localtime: Wed Feb 11:10: +14 2009
For more precise timeing, read perldoc -q profile.
See also Time-HiRes and for a *nix-ish flavor, perldoc -q time in (perlfaq8.pod) at "How can I measure time under a second?"
Update: ...or see oshalla's, above.
In reply to Re: Script execution time
by ww
in thread Script execution time
by velusamy
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |