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


Groups > comp.lang.python > #38406

Re: Curious to see alternate approach on a search/replace via regex

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.003
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'calls.': 0.07; 'sanity': 0.07; 'python': 0.09; 'arguments,': 0.09; 'filed': 0.09; 'learner': 0.09; 'oh,': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'thread': 0.11; '2.7:': 0.16; '4:59': 0.16; 'caching': 0.16; 'fwiw': 0.16; 'language)': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'subject:search': 0.16; 'wrote:': 0.17; 'basically': 0.17; 'exists': 0.17; 'module,': 0.17; 'pointed': 0.17; 'thu,': 0.17; '(or': 0.18; 'feb': 0.19; 'code.': 0.20; 'exists.': 0.22; 'setup.': 0.22; 'posted': 0.22; 'header:User-Agent:1': 0.26; 'looks': 0.26; 'header:X-Complaints-To:1': 0.28; 'went': 0.28; 'subject:/': 0.28; 'all.': 0.28; 'initial': 0.28; 'post': 0.28; "d'aprano": 0.29; 'steven': 0.29; 'case,': 0.29; "i'm": 0.29; 'fri,': 0.30; 'function': 0.30; 'to:addr:python-list': 0.33; 'done': 0.34; 'whatever': 0.35; 'fastest': 0.35; 'moved': 0.35; 'pm,': 0.35; 'there': 0.35; 'received:org': 0.36; 'except': 0.36; 'serve': 0.36; 'but': 0.36; "didn't": 0.36; 'charset:us-ascii': 0.36; 'bad': 0.37; 'does': 0.37; 'two': 0.37; 'being': 0.37; 'previous': 0.37; 'far': 0.37; 'subject:: ': 0.38; 'some': 0.38; 'nothing': 0.38; 'sure': 0.38; 'to:addr:python.org': 0.39; 'takes': 0.39; 'header:Received:5': 0.40; 'your': 0.60; 'matter': 0.61; 'future.': 0.62; 'day.': 0.63; 'confirm': 0.64; 'savings': 0.75; 'absolutely': 0.84; '+1100': 0.84; '2013': 0.84; 'gray': 0.84; 'habits.': 0.84; 'otten': 0.84; 'received:sd.cox.net': 0.84; 'subject:via': 0.84; 'thing...': 0.84
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From rh <richard_hubbe11@lavabit.com>
Subject Re: Curious to see alternate approach on a search/replace via regex
Date Thu, 7 Feb 2013 21:35:33 -0800
References <mailman.1426.1360187770.2939.python-list@python.org> <511319c7$0$21812$c3e8da3$76491128@news.astraweb.com> <mailman.1437.1360207874.2939.python-list@python.org> <51142e96$0$6512$c3e8da3$5496439d@news.astraweb.com> <mailman.1460.1360278819.2939.python-list@python.org> <51143feb$0$29974$c3e8da3$5496439d@news.astraweb.com> <mailman.1463.1360284981.2939.python-list@python.org> <51146ab6$0$30002$c3e8da3$5496439d@news.astraweb.com>
Mime-Version 1.0
Content-Type text/plain; charset=US-ASCII
Content-Transfer-Encoding 7bit
X-Gmane-NNTP-Posting-Host ip68-227-87-145.sb.sd.cox.net
User-Agent dsodnetnin
X-Mailer EZnn0.37p
X-Newsreader EZnn0.37p
X-Gmane-NNTP-Posting-Host EZnn0.37p
Original-Received from slem by 1.1 with local
X-No-Archive yes
Archive no
X-Archive expiry=11
X-Archive encrypt
X-Operating-System Barebones_6.1
X-Gmane-NNTP-Posting-Host 192.168.1.1
X-NNTP-Posting-Host 192.168.1.1
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.1475.1360301738.2939.python-list@python.org> (permalink)
Lines 48
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1360301738 news.xs4all.nl 6873 [2001:888:2000:d::a6]:39661
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:38406

Show key headers only | View raw


On Fri, 08 Feb 2013 14:02:14 +1100
Steven D'Aprano <steve+comp.lang.python@pearwood.info> wrote:

> Ian Kelly wrote:
> 
> > On Thu, Feb 7, 2013 at 4:59 PM, Steven D'Aprano
> > <steve+comp.lang.python@pearwood.info> wrote:
> >> Oh, one last thing... pulling out "re.compile" outside of the
> >> function does absolutely nothing. You don't even compile anything.
> >> It basically looks up that a compile function exists in the re
> >> module, and that's all.
> > 
> > Using Python 2.7:
> [...]
> > Whatever caching is being done by re.compile, that's still a 24%
> > savings by moving the compile calls into the setup.
> 
> That may or may not be the case, but rh didn't compile anything. He
> moved "re.compile" literally, with no arguments, out of the timing
> code. That clearly does nothing except confirm that re.compile exists.

My initial post has the function and in there are two re.compile calls.
I moved those out of the function and see repeatable time efficiency
improvements.

FWIW the fastest so far was posted by Peter Otten and didn't
use regex.

As a new learner of python (or any language) I like to know what
habits will serve me well into the future. So the only reason I look
at the time it takes is as a sanity check to make sure I'm not
learning bad habits.  In this case someone else pointed out time
comparisons and off the thread went into timings!

I did take note of your previous post using timeit and filed
that away into the gray matter for some other day.

> 
> 
> 
> -- 
> Steven
> 


-- 

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


Thread

Re: Curious to see alternate approach on a search/replace via regex Demian Brecht <demianbrecht@gmail.com> - 2013-02-06 13:55 -0800
  Re: Curious to see alternate approach on a search/replace via regex Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-02-07 03:04 +0000
    Re: Curious to see alternate approach on a search/replace via regex rh <richard_hubbe11@lavabit.com> - 2013-02-06 19:31 -0800
      Re: Curious to see alternate approach on a search/replace via regex Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-02-08 09:45 +1100
        Re: Curious to see alternate approach on a search/replace via regex rh <richard_hubbe11@lavabit.com> - 2013-02-07 15:13 -0800
          Re: Curious to see alternate approach on a search/replace via regex Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-02-08 10:59 +1100
            Re: Curious to see alternate approach on a search/replace via regex Ian Kelly <ian.g.kelly@gmail.com> - 2013-02-07 17:55 -0700
              Re: Curious to see alternate approach on a search/replace via regex Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-02-08 14:02 +1100
                Re: Curious to see alternate approach on a search/replace via regex rh <richard_hubbe11@lavabit.com> - 2013-02-07 21:35 -0800
            Re: Curious to see alternate approach on a search/replace via regex Ian Kelly <ian.g.kelly@gmail.com> - 2013-02-07 18:08 -0700
            Re: Curious to see alternate approach on a search/replace via regex rh <richard_hubbe11@lavabit.com> - 2013-02-07 21:57 -0800
            Re: Curious to see alternate approach on a search/replace via regex Ian Kelly <ian.g.kelly@gmail.com> - 2013-02-08 01:21 -0700
              Re: Curious to see alternate approach on a search/replace via regex Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-02-08 22:43 +1100
                Re: Curious to see alternate approach on a search/replace via regex Ian Kelly <ian.g.kelly@gmail.com> - 2013-02-08 09:26 -0700
            Re: Curious to see alternate approach on a search/replace via regex Serhiy Storchaka <storchaka@gmail.com> - 2013-02-15 22:58 +0200
            Re: Curious to see alternate approach on a search/replace via regex rh <richard_hubbe11@lavabit.com> - 2013-02-26 11:20 -0800
        Re: Curious to see alternate approach on a search/replace via regex Dave Angel <davea@davea.name> - 2013-02-08 01:27 -0500
    Re: Curious to see alternate approach on a search/replace via regex jmfauth <wxjmfauth@gmail.com> - 2013-02-07 03:08 -0800
      Re: Curious to see alternate approach on a search/replace via regex Chris Angelico <rosuav@gmail.com> - 2013-02-07 23:44 +1100

csiph-web