Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Question with time calculation

Status
Not open for further replies.

GeniuS22

MIS
May 25, 2002
29
CA
I know that
$time=localtime(time);
print $time;

it works and prints the entire time , date ......

1- I would to know how to calculate milliseconds
2- And how to calculate the time lenght of a function in milliseconds (cant seem to quite get it right!)

ex: file scan of entire hard drive (the lenght of that procedure)

Please help!

thanks for all the help in advance Knowledge is the first step to Greatness!!!
 
use Benchmark;
use Time::HiRes;

will do what you want. both are covered in the perldocs.

jaa
 
#!c:/Perl/bin/perl -w
use strict;
# using one of justice41 sugjested module
use Benchmark;
my $t0 = new Benchmark;
# do stuff here ...
my $t1 = new Benchmark;
my $td = timediff($t1, $t0);
print "the code took:",timestr($td),"\n"; ---------------------------------------
wmail.jpg


someone knowledge ends where
someone else knowledge starts
 
And similarly using Time::HiRes

use Time::HiRes qw(gettimeofday tv_interval);
my $t0 = [gettimeofday()];
sleep(4);
my $t1 = [gettimeofday()];
my $t0_t1 = tv_interval $t0, $t1;
print "That took: $t0_t1 seconds.\n";

This outputs:

That took: 4.004532 seconds.

jaa
 
#!c:/perl/bin/perl -w
#this also works for process time
use Win32;
use strict;
my $time1 = Win32::GetTickCount();
# do stuff
my $time2 = Win32::GetTickCount();
my $process_time = $time2 - $time1;
print "it took $process_time milliseconds";
---------------------------------------
wmail.jpg


someone knowledge ends where
someone else knowledge starts
 
Thank you very much guys
I have now 3 ways of doing it
Thanks a lot guys!! Knowledge is the first step to Greatness!!!
 
Thank you very much guys
I have now 3 ways of doing it
Knowledge is the first step to Greatness!!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top