Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #48643

Re: Why is regex so slow?

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!xlned.com!feeder3.xlned.com!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <skip.montanaro@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.016
X-Spam-Evidence '*H*': 0.97; '*S*': 0.00; 'subject:Why': 0.09; 'suggestions:': 0.09; 'cc:addr:python-list': 0.11; '(use': 0.16; 'from:addr:pobox.com': 0.16; 'from:addr:skip': 0.16; 'subject:slow': 0.16; 'sender:addr:gmail.com': 0.17; 'split': 0.19; 'seems': 0.21; 'cc:addr:python.org': 0.22; 'creating': 0.23; 'skip': 0.24; 'cc:2**0': 0.24; 'cc:no real name:2**0': 0.24; 'header:In-Reply-To:1': 0.27; 'matching': 0.30; 'message- id:@mail.gmail.com': 0.30; 'beginning': 0.33; 'could': 0.34; 'but': 0.35; 'received:google.com': 0.35; 'subject:?': 0.36; 'easily': 0.37; 'does': 0.39; 'first': 0.61; 'obvious': 0.74; 'yourself': 0.78
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type; bh=RuMEVYNj6rMQoFJIFuEs0MxuC7fuQesSPI3UiPf0URQ=; b=EXiTUP/ngYqcvM5NKXQN4RsWOM0ccKtRbILg6A0M/a4A8h2jbSWdUP16Kyg4MkL/kX M5xlrKopY9vqt6scmhmLE/18gSoSq0aqAMQyr37kdzqSFYRhZzT1S0uz3Gx9vb8SRzL4 gk9sI1NJG2r8ygG8896kQTIvgxyBcYBTV/89Yr4Hukko29Ldw14SaOC2UTDO7GzS/aGo 2uZxDWrGoypsBm+GiZHvDMClifB/ECHgf8KPf+N3Bk1LCrjoHyz5O4iWn1yQ/T0J8T92 CgMABqEZPeTmBDBLHTgv/HmIHVRwM6U5m4DpoHkTL/Egj8qx7jf8RnoEVW8/VfS4rIYY zokQ==
MIME-Version 1.0
X-Received by 10.50.9.7 with SMTP id v7mr8181687iga.51.1371574886454; Tue, 18 Jun 2013 10:01:26 -0700 (PDT)
Sender skip.montanaro@gmail.com
In-Reply-To <kpq2r9$gg6$1@panix2.panix.com>
References <kpq2r9$gg6$1@panix2.panix.com>
Date Tue, 18 Jun 2013 12:01:26 -0500
X-Google-Sender-Auth M6iF1LWpKOv31KwZkVB9bZ9fjjo
Subject Re: Why is regex so slow?
From Skip Montanaro <skip@pobox.com>
To Roy Smith <roy@panix.com>
Content-Type text/plain; charset=UTF-8
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 <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.3543.1371574888.3114.python-list@python.org> (permalink)
Lines 12
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1371574888 news.xs4all.nl 15917 [2001:888:2000:d::a6]:57758
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:48643

Show key headers only | View raw


> I don't understand why the first way is so much slower.

I have no obvious answers, but a couple suggestions:

1. Can you anchor the pattern at the beginning of the line?  (use
match() instead of search())
2. Does it get faster it you eliminate the "(.*)" part of the pattern?
 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.

Skip

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Why is regex so slow? roy@panix.com (Roy Smith) - 2013-06-18 12:45 -0400
  Re: Why is regex so slow? Skip Montanaro <skip@pobox.com> - 2013-06-18 12:01 -0500
  Re: Why is regex so slow? Roy Smith <roy@panix.com> - 2013-06-18 13:08 -0400
  Re: Why is regex so slow? Chris Angelico <rosuav@gmail.com> - 2013-06-19 03:20 +1000
    Re: Why is regex so slow? Johannes Bauer <dfnsonfsduifb@gmx.de> - 2013-06-18 20:10 +0200
      Re: Why is regex so slow? Roy Smith <roy@panix.com> - 2013-06-18 12:40 -0700
      Re: Why is regex so slow? André Malo <ndparker@gmail.com> - 2013-06-18 21:59 +0200
        Re: Why is regex so slow? André Malo <ndparker@gmail.com> - 2013-06-18 22:13 +0200
  Re: Why is regex so slow? MRAB <python@mrabarnett.plus.com> - 2013-06-18 18:31 +0100
  Re: Why is regex so slow? Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-06-18 18:34 +0100
    Re: Why is regex so slow? roy@panix.com (Roy Smith) - 2013-06-18 15:21 -0400
      Re: Why is regex so slow? MRAB <python@mrabarnett.plus.com> - 2013-06-18 20:49 +0100
  Re: Why is regex so slow? Rick Johnson <rantingrickjohnson@gmail.com> - 2013-06-18 12:21 -0700
  Re: Why is regex so slow? Antoine Pitrou <solipsis@pitrou.net> - 2013-06-18 20:05 +0000
    Re: Why is regex so slow? Roy Smith <roy@panix.com> - 2013-06-18 13:23 -0700
      Re: Why is regex so slow? Duncan Booth <duncan.booth@invalid.invalid> - 2013-06-19 13:21 +0000
        Re: Why is regex so slow? Roy Smith <roy@panix.com> - 2013-06-19 12:55 -0700
    Re: Why is regex so slow? Grant Edwards <invalid@invalid.invalid> - 2013-06-18 20:30 +0000
      Re: Why is regex so slow? Terry Reedy <tjreedy@udel.edu> - 2013-06-18 17:29 -0400
      Re: Why is regex so slow? Johannes Bauer <dfnsonfsduifb@gmx.de> - 2013-06-19 10:29 +0200
  Re: Why is regex so slow? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-06-19 01:51 +0000
    Re: Why is regex so slow? Dave Angel <davea@davea.name> - 2013-06-18 22:11 -0400
      Re: Why is regex so slow? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-06-19 03:16 +0000

csiph-web