[kw-pm] Perl - optimizing code

Robert Pike roberthpike at yahoo.com
Fri Feb 2 12:31:39 PST 2018


Hi all,     I've been presented with the following code and I'm looking at ways of speeding it up (just this particular segment). A lot of data is running through this segment of code and placing a time print before and after it shows it takes approximately 4 minutes to complete. Any suggestions on how to speed up the processing of it? Some attempts have been made in the past from documentation and such found in the main script. I'm hoping to hear various opinions and ways different people might tackle different sections of the attached segment. Thanks in advance for suggestions. 
Rob
for ($sCurrLevel=0;$sCurrLevel<=$startLimit;$sCurrLevel++) {        @topLevel = split(/\~/, ${$aLevels}[$sCurrLevel]);        $topCnt = $#topLevel;        for ($tCnt=0;$tCnt<=$topCnt;$tCnt++) {            @detailLevel = split(/\,/, $topLevel[$tCnt]);            if ($sCurrLevel > 0) {                @lastLevel = split(/[\~,]/, ${$aLevels}[$sCurrLevel-1]);                $calcVal = $#{$drillDownMapping{$lastLevel[$tCnt]}};                for ($dcCnt=0;$dcCnt<=$#detailLevel;$dcCnt++) {                    $detValue = $detailLevel[$dcCnt];                    if ($lastLevel[$tCnt] ne "X" && $detValue ne "X") {                        if ($matchLevel == -1) {                            if (${$aQ}->param("drillOnID") eq $detValue) { $matchLevel = $sCurrLevel; }                        }                        $idMapping{$detValue} =  $lastLevel[$tCnt];                        $calcVal += 1;                        $drillDownMapping{$lastLevel[$tCnt]}[$calcVal] = $detValue;                    }                }                undef (@lastLevel);            }            #---------------------------------            if ($#detailLevel <= 0) {                $currLevelList[$sCurrLevel][$tCnt][0] = $detailLevel[0];            } else {                push (@{$currLevelList[$sCurrLevel][$tCnt]}, @detailLevel);            }            undef(@detailLevel);        }        undef (@topLevel);    }
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.pm.org/pipermail/kw-pm/attachments/20180202/c579583e/attachment.html>


More information about the kw-pm mailing list