Precompiled regular expressions slower?
Sean 'Shaleh' Perry
shalehperry at attbi.com
Tue Feb 26 12:49:59 EST 2002
More information about the Python-list mailing list
Tue Feb 26 12:49:59 EST 2002
- Previous message (by thread): Precompiled regular expressions slower?
- Next message (by thread): Precompiled regular expressions slower?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
> > Possible mechanism for what's happening: > > - Setting up a compiled re object takes time X > > - Executing one search using compiled re object takes time x > > - Thus, n searches using compiled object takes X + (n * x) > > - Executing search using re.search() takes time y > > - "Setup" is included in that time (basically consists of > following reference to re.search()) > > - Thus, n searches using re.search() takes n * y > Actually, it is more odd. sre.py does compile the regex and stores it in an internal dictionary if you just do re.search(r'blah', foo). So either way the regex is getting compiled. Compiling the regex and storing it in a local variable should save you a function call or two and a dictionary lookup. Perhaps Peter should post the relevant code so we can see what is actually happening for ourselves?
- Previous message (by thread): Precompiled regular expressions slower?
- Next message (by thread): Precompiled regular expressions slower?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list