晕,同一段脚本,在5.8.8和5.10.1环境下,性能相差100倍

功能是对文件A,根据文件B进行过滤,代码如下:
sub filterFile
{
        my ($processFile,$filterFile1,$outputFile) = @_;
        my %hashFile;
        my $fileBuildTime='123456';
       
        open (OUTFILE, ">>${outputFile}" or die "can't open file: $outputFile";
       
        open FH, "<$filterFile1" or die "can't open file: $filterFile1";
    while (<FH>
     {
         chomp;
        $hashFile{$_} = 1;
     }
    close (FH);
       
        open FH, "<$processFile" or print "can't open file: $processFile";

     
     my $reg=join '|',keys %hashFile;
     print "reg isreg\n";
    while (<FH> {
               if (/($reg)/)
       {
               print OUTFILE "${fileBuildTime}\t$_" ;
               $rowCNT++;
       }
      }
        

     
close (FH);
close(OUTFILE);
}      

在5.10.1环境下,1分钟,而在5.8.8环境下,竟然需要1个多小时,求解,到底是那个地方导致2个版本的性能差异这么大?

作者: fikong2005   发布时间: 2011-05-28

如果真是这个函数的原因,而且 B 文件不是非常大的话那估计只能是 if (/($reg)/) 这里了。5.10 的 RE engine 改动很大,你多测试测试

作者: zhlong8   发布时间: 2011-05-28