logo       

Slow regular-expression engine: msg#02390

ruby-talk

Subject: Slow regular-expression engine

This Awk code takes less than one hundredth of a second to run:

BEGIN {

regex = \
"o?o?o?o?o?o?o?o?o?o?o?o?o?o?" \
"o?o?o?o?o?o?o?o?o?o?o?o?o?" \
"ooooooooooooooooooooooooooooo"

print "ooooooooooooooooooooooooooooo" ~ regex

}


This Ruby code takes 27.5 seconds:

t = Time.now

regex = Regexp.new(
"o?o?o?o?o?o?o?o?o?o?o?o?o?o?" +
"o?o?o?o?o?o?o?o?o?o?o?o?o?" +
"ooooooooooooooooooooooooooooo" )

p "ooooooooooooooooooooooooooooo" =~ regex

puts "#{ Time.now - t } seconds"


See http://swtch.com/~rsc/regexp/regexp1.html

<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | Mail Home | sitemap | FAQ | advertise