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

From rh <richard_hubbe11@lavabit.com>
Subject Re: Curious to see alternate approach on a search/replace via regex
Date 2013-02-07 21:35 -0800
References (3 earlier) <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>
Newsgroups comp.lang.python
Message-ID <mailman.1475.1360301738.2939.python-list@python.org> (permalink)

Show all headers | 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