Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #38389
| Path | csiph.com!usenet.pasdenom.info!news.albasani.net!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <ian.g.kelly@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.023 |
| X-Spam-Evidence | '*H*': 0.95; '*S*': 0.00; '"""': 0.05; 'python': 0.09; 'oh,': 0.09; '2.7:': 0.16; '4:59': 0.16; 'caching': 0.16; 'subject:search': 0.16; 'wrote:': 0.17; 'basically': 0.17; 'exists': 0.17; 'module,': 0.17; 'thu,': 0.17; '>>>': 0.18; 'feb': 0.19; 'import': 0.21; 'setup.': 0.22; 'header:In-Reply-To:1': 0.25; 'looks': 0.26; 'message-id:@mail.gmail.com': 0.27; 'subject:/': 0.28; 'all.': 0.28; "d'aprano": 0.29; 'steven': 0.29; 'function': 0.30; 'skip:8 10': 0.32; 'to:addr:python-list': 0.33; 'received:google.com': 0.34; 'done': 0.34; 'whatever': 0.35; 'pm,': 0.35; 'received:209.85': 0.35; 'does': 0.37; 'being': 0.37; 'received:209': 0.37; 'subject:: ': 0.38; 'to:addr:python.org': 0.39; 'url:a': 0.72; 'savings': 0.75; 'absolutely': 0.84; '2013': 0.84; 'subject:via': 0.84; 'thing...': 0.84; 'to:name:python': 0.84 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:mime-version:in-reply-to:references:from:date:message-id :subject:to:content-type; bh=sNOuy9B3UcNBkm/hNUZg/c2vomGakCee5xVs9btLiEs=; b=b1lfsWnzp7/RXEzuEI5Wdl61k0NFszUyYnBjQAJkXniBZajc4mwBympLMMvOFkoWzL ozzO3NrwLdfVRYWzmH3zFcXd+uBZmpzusONWzEwFjuNZUPKAFQrz0aRosMmHpx7hW8pu 3yMOtgExNrLsGvNKpdFmyspVYz/GF3irojKphHYsjdnoTRWI5ifzJEekzxFdlk7jIw1h 5OxnxsHevTK5OoG9QL79GmkUc4SAwUYhjUBmXGRYLMB8x5lvN7J3PuDGx9GvIjlgVrbR VSx5IFxzBE78soG5JNPCrqXHBqgRiJA5svtSVgBUM0j2SKrYVz6s9xKCfeTV/1BOuWUo MZvg== |
| X-Received | by 10.66.87.67 with SMTP id v3mr11204938paz.63.1360284972366; Thu, 07 Feb 2013 16:56:12 -0800 (PST) |
| MIME-Version | 1.0 |
| In-Reply-To | <51143feb$0$29974$c3e8da3$5496439d@news.astraweb.com> |
| 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> |
| From | Ian Kelly <ian.g.kelly@gmail.com> |
| Date | Thu, 7 Feb 2013 17:55:31 -0700 |
| Subject | Re: Curious to see alternate approach on a search/replace via regex |
| To | Python <python-list@python.org> |
| Content-Type | text/plain; charset=ISO-8859-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.1463.1360284981.2939.python-list@python.org> (permalink) |
| Lines | 29 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1360284981 news.xs4all.nl 6855 [2001:888:2000:d::a6]:36187 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:38389 |
Show key headers only | View raw
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:
>>> t1 = Timer("""
... nx = re.compile(r'https?://(.+)$')
... v = nx.search(u).group(1)
... ux = re.compile(r'([-:./?&=]+)')
... ux.sub('_', v)""", """
... import re
... u = 'http://alongnameofasite1234567.com/q?sports=run&a=1&b=1'""")
>>> t2 = Timer("""
... v = nx.search(u).group(1)
... ux.sub('_', v)""", """
... import re
... nx = re.compile(r'https?://(.+)$')
... ux = re.compile(r'([-:./?&=]+)')
... u = 'http://alongnameofasite1234567.com/q?sports=run&a=1&b=1'""")
>>> min(t1.repeat())
11.625409933385388
>>> min(t2.repeat())
8.825254885746652
Whatever caching is being done by re.compile, that's still a 24%
savings by moving the compile calls into the setup.
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll 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