Program inefficiency?

Carsten Haese carsten at uniqsys.com
Sat Sep 29 17:43:04 CEST 2007


On Sat, 2007-09-29 at 15:22 +0000, hall.jeff at gmail.com wrote:
> [...]
> def replacecycle(starttext):
>     p1= re.compile('(href=|HREF=)+(.*)(#)+(.*)( )+(.*)(">)+')
>     p2= re.compile('(name=")+(.*)( )+(.*)(">)+')
>     p3= re.compile('(href=|HREF=)+(.*)(#)+(.*)(\')+(.*)(">)+')
>     p4= re.compile('(name=")+(.*)(\')+(.*)(">)+')
>     p5= re.compile('(href=|HREF=)+(.*)(#)+(.*)(-)+(.*)(">)+')
>     p6= re.compile('(name=")+(.*)(-)+(.*)(">)+')
>     p7= re.compile('(href=|HREF=)+(.*)(#)+(.*)(<)+(.*)(">)+')
>     p8= re.compile('(name=")+(.*)(<)+(.*)(">)+')
>     p7= re.compile('(href=|HREF=")+(.*)(#)+(.*)(:)+(.*)(">)+')
>     p8= re.compile('(name=")+(.*)(:)+(.*)(">)+')
>     p9= re.compile('(href=|HREF=")+(.*)(#)+(.*)(\?)+(.*)(">)+')
>     p10= re.compile('(name=")+(.*)(\?)+(.*)(">)+')
>     p100= re.compile('(a name=)+(.*)(-)+(.*)(></a>)+')
> [...]

One obvious opportunity for optimization is to compile those re's only
once at the beginning of the program instead of every time
replacecycle() is called (which is inexplicably called 13 times for each
file).

-- 
Carsten Haese
http://informixdb.sourceforge.net





More information about the Python-list mailing list