in reply to Performance revision needed

I would not call the following optimization. You don't really give enough info to optimize your code. The following just eliminates some wasted cycles and stylistically improves the code. This should improve performance also.

This is untested off the cuff code

#!/usr/bin/perl use warnings; use strict; # move declarations out of loop # my ( $date, $atime, $etime, $mth, $port, $attrID, $value ); my ( $HH, $MM, $SS ); my ( $year, $month, $day ); my @entry ; while (<SSLOG>) { # chomp one item not seven chomp; ($date, $atime, $etime, $mth, $port, $attrID, $value) = split /;/, $_ ; # combine conditions into one # could be optimized by knowing the data # and short circuiting # if ( ($Conf[7]=~ /NO/i) && ($value!= /^0/) or ( $Conf[7] =~ /YES/i) ) { # Move time computation inside conditional # # Convert the log time to UTC time ( $HH, $MM, $SS ) = split ( /:/, $etime ); ( $year, $month, $day ) = $date =~ m/^(.{4})(.{2})(.*)/; $month -= 1; $Time= timelocal($SS, $MM, $HH, $day, $month, $year); # Build a hash of MTypeHandles with their unique ports $Hash{$mth}{$port}++; $attrID =~ s/\s*//g; $port =~ s/\s*//g; # Remove unnecessary condition # # if ( $port =~ /\-/ ) { # $port =~ s/\-//; # } $port =~ s/\-//; #remove unnecessary variable # #$key = $attrID; #$val = $DS_Info{$key}; # $val = $DS_Info{$attrID}; #Remove unnecessary join. #$val = join ( "", $val, $port ); # $val .= $port; # Remove unnecessary variable # @entry = ( $Time, $mth, $val, $value ); # # This is a big array you are making # What do you do with it? # Is there any other choice # # Populate the data array # push @Data, [@entry]; # push @Data, [ $Time, $mth, $val, $value ]; } }

Replies are listed 'Best First'.
Re: Re: Performance revision needed
by Anonymous Monk on Jan 02, 2003 at 19:40 UTC
    Thank you rir,

    Your suggestions and a combination of the others have improved performance greatly.

    Thanks again rir, and others who who posted suggestions