Title: Want to reduce the speed of execution in Perl script.

Dear All,

Suppose I have a log length tab-separated file, in this file I have to make the average of numbers based on certain parameters

as hour, group name and monitor name. This program takes long time in running.

my ($infile) = @ARGV;
$filebuf1 = file_read($infile);
my (@group_monitor) = $filebuf1 =~ m/\d+\/\d+\/\d+\t(\d+\t.*?\t.*?)\t.*?\n/sg; ##This is taking time,group name and monitor name into an array from the file.

my @unique = grep { ! $seen{ $_ }++ } @group_monitor; ##This is taking unique values of that array.
foreach my $key(@unique)
{
my $tempbuf1;
my $cnt = 0;
my $total=0;
my $tstep1=0;
my $tstep2=0;
my $tstep3=0;
my $tstep4=0;
my $tstep5=0;
my $tstep6=0;
my $steps;
my $prev;
my $avg, $avstep1=0, $avstep2=0, $avstep3=0, $avstep4=0, $avstep5=0, $avstep6=0;
my $filebuf2;
my $date;
my $hr;
my $monitor;
my $group;

($fir,$sec,$thr) = split(/\t/,$key); ## This is spliting that value based on tab space.
system(qq~agrep "$fir\t$sec\t" $outfile > tmp~); ## agrep is an external utility to find search pattern in a file and transfer it into other file.

system(qq~agrep "$thr" tmp > tmp1~); ## agrep is more faster than regular _expression_.

open(FIN,"<tmp") || die "Unable to open file :  $filepath";

my $cnt = 0;
while($line=<FIN>)                              # go through all line in file
{
if($line =~ m/\t/g)
{
($date,$hr,$monitor,$group,$steps,$total1,$step1,$step2,$step3,$step4,$step5,$step6) = split(/\t/,$line);
$tstep1=$step1+$tstep1;
$tstep2=$step2+$tstep2;
$tstep3=$step3+$tstep3;
$tstep4=$step4+$tstep4;
$tstep5=$step5+$tstep5;
$tstep6=$step6+$tstep6;
$total = $total+$total1;
$cnt=$cnt+1;
}
}
$avg = sprintf "%.2f",$total/$cnt;              
$avstep1 = sprintf "%.2f",$tstep1/$cnt;
$avstep2 = sprintf "%.2f",$tstep2/$cnt;
$avstep3 = sprintf "%.2f",$tstep3/$cnt;
$avstep4 = sprintf "%.2f",$tstep4/$cnt;
$avstep5 = sprintf "%.2f",$tstep5/$cnt;
$avstep6 = sprintf "%.2f",$tstep6/$cnt;

switch ($steps)
{
case 1  { $filebuf3 .= "$date\t$hr\t$monitor\t$group\t$steps\t$avg\t$avstep1\n" }
case 2  { $filebuf3 .= "$date\t$hr\t$monitor\t$group\t$steps\t$avg\t$avstep1\t$avstep2\n" }
case 3  { $filebuf3 .= "$date\t$hr\t$monitor\t$group\t$steps\t$avg\t$avstep1\t$avstep2\t$avstep3\n" }
case 4  { $filebuf3 .= "$date\t$hr\t$monitor\t$group\t$steps\t$avg\t$avstep1\t$avstep2\t$avstep3\t$avstep4\n" }
case 5  { $filebuf3 .= "$date\t$hr\t$monitor\t$group\t$steps\t$avg\t$avstep1\t$avstep2\t$avstep3\t$avstep4\t$avstep5\n" }

case 6  { $filebuf3 .= "$date\t$hr\t$monitor\t$group\t$steps\t$avg\t$avstep1\t$avstep2\t$avstep3\t$avstep4\t$avstep5\t$avstep6\n" }


close(FIN);
}
$outfile1= "Ext1.txt";
file_write($outfile1, $filebuf3); ## This is used to write the content into the output file.

Does anyone is having different idea about reducing the speed in execution? This I am finding out about how to reduce the speed.

Thanks & Regards,
Seema.


If you are not an intended recipient of this e-mail, please notify the sender, delete it and do not read, act upon, print, disclose, copy, retain or redistribute it. Click here for important additional terms relating to this e-mail.     http://www.ml.com/email_terms/

_______________________________________________
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to