in reply to Re^4: The Deceiver
in thread Why does a Perl 5.6 regex run a lot slower on Perl 5.8?

If I remove the backreference by changing the regex in my example to $n++ while ($s =~ /(.*?)RRRR/sg);, I get the following:
time ~/bin/perl5.8.0 reg.pl
500 matches

real    0m0.018s
user    0m0.010s
sys     0m0.010s

time ~/bin/perl5.6.1 reg.pl
1 matches

real    0m0.015s
user    0m0.010s
sys     0m0.000s

So at least in this case Perl 5.8.0 doesn't have a speed problem. I don't know exactly what's going on in your code though.

Replies are listed 'Best First'.
Re^6: The Deceiver
by itub (Priest) on Aug 13, 2004 at 15:27 UTC
    Sorry to reply to myself, but I think I found something. The problem seems to manifest itself more clearly when using the /i modifier and the regex fails. It seems the engine is wasting a lot of time normalizing case.

    $s = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxyyyRRRyyyy\n" x 300; $n = 0; $n++ while ($s =~ /(.*?)RRRR/isg); print "$n matches\n";

    To summarize: 5.6.1: 0 matches, 0.32 s; 5.8.0: 0 matches, 2.2 s.

    But note that if I change the regex to /x(.*?)RRRR/isg the results are reversed: 5.6.1: 9.2 s; 5.8.0: 1.4 s. That's because now 5.6.1 can't get away with the fake anchor. Interesting...