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 ]; } }

In reply to Re: Performance revision needed by rir
in thread Performance revision needed by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.