From: Wai-Sun Chia Date: 2002-10-07T17:30:15+09:00 Subject: Re: regex speed Here's my take: RH7.3 box, Perl 5.6.1, Ruby 1.7.3 (2002-09-13) $ perl -0 -ne'print 1 if /A.+\n+B/s' str # 0m0.517s $ ruby -0 -ne'print 1 if /A.+\n+B/m' str # 0m5.715s $ perl -0 -ne'print 1 if /A.+\n.+\nB/s' str # 0m5.854s $ ruby -0 -ne'print 1 if /A.+\n.+\nB/m' str # 0m3.574s Heh. So Ruby 1.7.3 overtakes Perl for complex regexes??!! ;-) This is a Xeon 1.8GHz/512MB box. David Garamond wrote: > i am noticing ruby is much slower than perl when matching patterns with > two or more quantifier (+ or *). consider this string: > > $ ruby -0 -ne 'print "A"*3,"\n"*10000,"B"*10,"\n"*10000' > str > > and matching this string: > > $ perl -0 -ne'print 1 if /A.+\n+B/s' str # 0m1.682s > $ ruby -0 -ne'print 1 if /A.+\n+B/m' str # 0m12.468s > $ perl -0 -ne'print 1 if /A.+\n.+\nB/s' str # 0m1.368s > $ ruby -0 -ne'print 1 if /A.+\n.+\nB/m' str # 0m11.427s > > php (pcre) speed is somewhere in between. > > of course, with patterns like /A.+\n+.+B/ or those with more quantifiers > both become very slow, but i suspect perl is still faster then ruby > especially when there are fewer ".+" and more "SINGLECHAR+" subpatterns. > i even have one case where perl takes less than a second and ruby takes > more than five minutes (i don't know for sure, i interrupted the process > so ruby never finished). > > note that i'm not implying anything though, because i understand perl's > regex engine has undergone a long period of tweaking and optimization. > -- Wai-Sun "Squidster" Chia Sr. OpenSource Consultant, M.Sc., RHCE Advanced Computing & Application Center Universiti Teknologi Malaysia