Path: csiph.com!usenet.pasdenom.info!news.albasani.net!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!194.109.133.86.MISMATCH!newsfeed.xs4all.nl!newsfeed3.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.007 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'pypi': 0.07; 'string': 0.09; 'lawrence': 0.09; 'methods,': 0.09; 'subject:Why': 0.09; '(and,': 0.16; 'from:addr:mrabarnett.plus.com': 0.16; 'from:addr:python': 0.16; 'from:name:mrab': 0.16; 'message- id:@mrabarnett.plus.com': 0.16; 'openoffice': 0.16; 'roy': 0.16; 'sane': 0.16; 'shot.': 0.16; 'subject:slow': 0.16; 'version?': 0.16; 'wrote:': 0.18; 'module': 0.19; 'header:User-Agent:1': 0.23; 'format,': 0.24; 'initial': 0.24; 'header:In-Reply-To:1': 0.27; 'installed': 0.27; 'tried': 0.27; 'url:bugs': 0.29; "i'm": 0.30; 'getting': 0.31; 'fighting': 0.31; 'overhead': 0.31; 'run': 0.32; 'url:python': 0.33; 'raw': 0.33; 'subject:?': 0.36; 'url:org': 0.36; 'too': 0.37; 'to:addr:python-list': 0.38; 'rather': 0.38; 'to:addr:python.org': 0.39; 'skip:p 20': 0.39; 'gone': 0.61; 'new': 0.61; 'header:Reply-To:1': 0.67; 'smith': 0.68; 'reply- to:no real name:2**0': 0.71; 'article': 0.77; 'reply- to:addr:python.org': 0.84; 'spreadsheet': 0.84 X-CM-Score: 0.00 X-CNFS-Analysis: v=2.1 cv=KrN0hwmN c=1 sm=1 tr=0 a=0nF1XD0wxitMEM03M9B4ZQ==:117 a=0nF1XD0wxitMEM03M9B4ZQ==:17 a=0Bzu9jTXAAAA:8 a=oyR3mlnJdzkA:10 a=ynY2aRLGfR4A:10 a=ihvODaAuJD4A:10 a=OUOv7kDek9cA:10 a=8nJEP1OIZ-IA:10 a=EBOSESyhAAAA:8 a=8AHkEIZyAAAA:8 a=APIjv3kaCL4A:10 a=BrDiTsk0AAAA:8 a=kVtXSAHBF41JJhMFYT0A:9 a=wPNLvfGTeEIA:10 a=VhVvL8HfBcoA:10 a=-hJg1tCh9CgA:10 X-AUTH: mrabarnett:2500 Date: Tue, 18 Jun 2013 20:49:46 +0100 From: MRAB User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:17.0) Gecko/20130509 Thunderbird/17.0.6 MIME-Version: 1.0 To: python-list@python.org Subject: Re: Why is regex so slow? References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list Reply-To: python-list@python.org 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: 54 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1371584976 news.xs4all.nl 15985 [2001:888:2000:d::a6]:60234 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:48663 On 18/06/2013 20:21, Roy Smith wrote: > In article , > Mark Lawrence wrote: > >> Out of curiousity have the tried the new regex module from pypi rather >> than the stdlib version? A heck of a lot of work has gone into it see >> http://bugs.python.org/issue2636 > > I just installed that and gave it a shot. It's *slower* (and, much > higher variation from run to run). I'm too exhausted fighting with > OpenOffice to get this into some sane spreadsheet format, so here's > the raw timings: > > Built-in re module: > 0:01.32 > 0:01.33 > 0:01.32 > 0:01.33 > 0:01.35 > 0:01.32 > 0:01.35 > 0:01.36 > 0:01.33 > 0:01.32 > > regex with flags=V0: > 0:01.66 > 0:01.53 > 0:01.51 > 0:01.47 > 0:01.81 > 0:01.58 > 0:01.78 > 0:01.57 > 0:01.64 > 0:01.60 > > regex with flags=V1: > 0:01.53 > 0:01.57 > 0:01.65 > 0:01.61 > 0:01.83 > 0:01.82 > 0:01.59 > 0:01.60 > 0:01.55 > 0:01.82 > I reckon that about 1/3 of that time is spent in PyArg_ParseTupleAndKeywords, just getting the arguments! There's a higher initial overhead in using regex than string methods, so working just a line at time will take longer.