yoganaut has asked for the wisdom of the Perl Monks concerning the following question:
Unrolling the inner loop like so, results in 3 second execution and appears to produce the same results. Why the 10x hit with the nested loops? What am I missing? Thanks.my @patterns = ("SDC: HUT time changed: 0", "BATT: Cap=0\\(watt-min\\) HUT=0\\(min\\) 0\\(hrs\ +\) state=GOOD->BAD", "BATT: Log battery system condition GOOD->BAD"); my @events; foreach my $line (@$srcRef) { foreach my $pattern (@patterns) { if ($line =~ /$pattern/) { push(@events, $line); last; } } }
foreach my $line (@$srcRef) { if ($line =~ /SDC: HUT time changed: 0/) { push(@events, $line); } elsif ($line =~ /BATT: Cap=0\(watt-min\) HUT=0\(min\) 0\(hrs\) + state=GOOD->BAD/) { push(@events, $line); } elsif ($line =~ /BATT: Log battery system condition GOOD->BAD/ +) { push(@events, $line); } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: performance explanation needed
by Zaxo (Archbishop) on May 04, 2005 at 23:48 UTC | |
|
Re: performance explanation needed
by Roy Johnson (Monsignor) on May 04, 2005 at 23:39 UTC |