Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.datemas.de!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.005 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'slow.': 0.09; 'subject:Why': 0.09; 'suggestions:': 0.09; 'to:addr:pobox.com': 0.09; 'to:addr:skip': 0.09; 'cc:addr:python-list': 0.11; 'bug': 0.12; 'assume': 0.14; '(use': 0.16; 'received:166.84': 0.16; 'received:166.84.1': 0.16; 'received:166.84.1.89': 0.16; 'received:mailbackend.panix.com': 0.16; 'received:panix.com': 0.16; 'roy': 0.16; 'subject:slow': 0.16; 'tempted': 0.16; 'wrote:': 0.18; 'module': 0.19; 'received:166': 0.19; 'split': 0.19; 'seems': 0.21; 'cc:addr:python.org': 0.22; 'creating': 0.23; '2.x': 0.24; 'skip': 0.24; '---': 0.24; 'cc:2**0': 0.24; 'cc:no real name:2**0': 0.24; 'least': 0.26; 'header:In-Reply-To:1': 0.27; 'tried': 0.27; 'matching': 0.30; "i'm": 0.30; '(which': 0.31; 'open': 0.33; 'beginning': 0.33; 'could': 0.34; 'received:66': 0.35; 'but': 0.35; "didn't": 0.36; 'charset:us- ascii': 0.36; 'subject:?': 0.36; 'easily': 0.37; 'performance': 0.37; 'pm,': 0.38; 'that,': 0.38; 'does': 0.39; 'skip:u 10': 0.60; 'first': 0.61; 'making': 0.63; 'header:Message-Id:1': 0.63; 'smith': 0.68; 'obvious': 0.74; 'yourself': 0.78; 'difference.': 0.84; 'email addr:panix.com': 0.84; '2013,': 0.91 Subject: Re: Why is regex so slow? Mime-Version: 1.0 (Apple Message framework v1283) Content-Type: text/plain; charset=us-ascii From: Roy Smith In-Reply-To: Date: Tue, 18 Jun 2013 13:08:52 -0400 Content-Transfer-Encoding: quoted-printable References: To: Skip Montanaro X-Mailer: Apple Mail (2.1283) Cc: python-list@python.org X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 30 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1371575342 news.xs4all.nl 15889 [2001:888:2000:d::a6]:60585 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:48644 On Jun 18, 2013, at 1:01 PM, Skip Montanaro wrote: >> I don't understand why the first way is so much slower. >=20 > I have no obvious answers, but a couple suggestions: >=20 > 1. Can you anchor the pattern at the beginning of the line? (use > match() instead of search()) That's one of the things we tried. Didn't make any difference. > 2. Does it get faster it you eliminate the "(.*)" part of the pattern? Just tried that, it also didn't make any difference. > It seems that if you find a line matching the first part of the > pattern, you could just as easily split the line yourself instead of > creating a group. At this point, I'm not so much interested in making this faster as = understanding why it's so slow. I'm tempted to open this up as a = performance bug against the regex module (which I assume will be = rejected, at least for the 2.x series). --- Roy Smith roy@panix.com