Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #50959
| Path | csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!ecngs!feeder2.ecngs.de!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <joshua.landau.ws@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.006 |
| X-Spam-Evidence | '*H*': 0.99; '*S*': 0.00; '(at': 0.04; 'anyway.': 0.05; 'string': 0.09; 'builtin': 0.09; 'translate': 0.10; 'cc:addr :python-list': 0.11; 'python': 0.11; 'def': 0.12; 'iterables': 0.16; 'iterated': 0.16; 'mappings,': 0.16; 'quote=true):': 0.16; 'str,': 0.16; 'trivially': 0.16; 'tuple,': 0.16; 'worst': 0.16; 'sender:addr:gmail.com': 0.17; 'wrote:': 0.18; 'basically': 0.19; 'passing': 0.19; 'cc:addr:python.org': 0.22; 'bytes': 0.24; 'replace': 0.24; 'cc:2**0': 0.24; 'second': 0.26; 'least': 0.26; 'header:In-Reply-To:1': 0.27; "doesn't": 0.30; 'characters': 0.30; 'fastest': 0.30; 'message-id:@mail.gmail.com': 0.30; "d'aprano": 0.31; 'really,': 0.31; 'steven': 0.31; 'lists': 0.32; 'could': 0.34; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'ordered': 0.36; 'method': 0.36; 'shows': 0.36; 'should': 0.36; '8bit%:86': 0.38; 'list,': 0.38; 'fact': 0.38; 'expect': 0.39; 'though,': 0.39; 'how': 0.40; 'back': 0.62; 'high': 0.63; 'july': 0.63; 'to:addr:gmail.com': 0.65; 'dict,': 0.84; 'faster.': 0.84; 'penalty': 0.84; 'subject:skip:S 10': 0.84; 'reasons,': 0.91; '2013': 0.98 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:from:date :x-google-sender-auth:message-id:subject:to:cc:content-type :content-transfer-encoding; bh=gWngf/grjBuECsfmba0hypEzINvdDa/Wa5qHg6va6oU=; b=Ypr37BRLlZQSVL9BRoIfArmi/6PzIuZqNsUDrvNZkRqs3v1PfSRP8Bg6yXOJ1VpavR qO600Rf7bf3Av5OMGJ5Fnpzf6eQ1CCblPeMiaJlGyfftPU54qmiYDM2h5r154CgypfvD 1GTh8WjvMqU9mFoaqSecdyIcslZ6dryYWqh6mHxHY8S8qv5a4nBm4U9w2bYjyHJXHqBn UOUIPaYYnuzjQsXk6pfSprnyQKm3BbahmP3RtEIWhG6lvvdicfEB1rpEdTyAncq/O/z7 IB/gElil20VmRjrgayKf0feLH5l8mLN7NtY3irWJY7GFDzDb1kTcJY2Szcp9OiXqTO2f r/AQ== |
| X-Received | by 10.152.45.65 with SMTP id k1mr9092058lam.78.1374319035643; Sat, 20 Jul 2013 04:17:15 -0700 (PDT) |
| MIME-Version | 1.0 |
| Sender | joshua.landau.ws@gmail.com |
| In-Reply-To | <ksbt1a$5q1$1@ger.gmane.org> |
| References | <mailman.4865.1374240179.3114.python-list@python.org> <51e967bb$0$29971$c3e8da3$5496439d@news.astraweb.com> <ksbt1a$5q1$1@ger.gmane.org> |
| From | Joshua Landau <joshua@landau.ws> |
| Date | Sat, 20 Jul 2013 12:16:35 +0100 |
| X-Google-Sender-Auth | EFDxWcZzKDgzd9VfrGMwy5tbFpU |
| Subject | Re: Find and Replace Simplification |
| To | Serhiy Storchaka <storchaka@gmail.com> |
| Content-Type | text/plain; charset=UTF-8 |
| Content-Transfer-Encoding | quoted-printable |
| Cc | python-list <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.4915.1374319043.3114.python-list@python.org> (permalink) |
| Lines | 35 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1374319043 news.xs4all.nl 15928 [2001:888:2000:d::a6]:50067 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:50959 |
Show key headers only | View raw
On 19 July 2013 18:29, Serhiy Storchaka <storchaka@gmail.com> wrote:
> 19.07.13 19:22, Steven D'Aprano написав(ла):
>
>> I also expect that the string replace() method will be second fastest,
>> and re.sub will be the slowest, by a very long way.
>
>
> The string replace() method is fastest (at least in Python 3.3+). See
> implementation of html.escape() etc.
def escape(s, quote=True):
if quote:
return s.translate(_escape_map_full)
return s.translate(_escape_map)
I fail to see how this supports the assertion that str.replace() is
faster. However, some quick timing shows that translate has a very
high penalty for missing characters and is a tad slower any way.
Really, though, there should be no reason for .translate() to be
slower than replace -- at worst it should just be "reduce(lambda s,
ab: s.replace(*ab), mapping.items()¹, original_str)" and end up the
*same* speed as iterated replace. But the fact that it doesn't have to
re-build the string every replace means that theoretically it should
be a lot faster.
¹ I realise this won't actually work for several reasons, and doesn't
support things like passing in lists as mappings, but you could
trivially support the important builtin types² and fall back to the
original for others, where the pure-python __getitem__ is going to be
the slowest part anyway.
² List, tuple, dict, str, bytes -- so basically just mappings and
ordered iterables
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Find and Replace Simplification Devyn Collier Johnson <devyncjohnson@gmail.com> - 2013-07-19 09:22 -0400
Re: Find and Replace Simplification Novocastrian_Nomad <gregory.j.baker@gmail.com> - 2013-07-19 06:38 -0700
Re: Find and Replace Simplification John Gordon <gordon@panix.com> - 2013-07-19 14:28 +0000
Re: Find and Replace Simplification Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-07-19 16:22 +0000
Re: Find and Replace Simplification Serhiy Storchaka <storchaka@gmail.com> - 2013-07-19 20:29 +0300
Re: Find and Replace Simplification Skip Montanaro <skip@pobox.com> - 2013-07-19 13:08 -0500
Re: Find and Replace Simplification Devyn Collier Johnson <devyncjohnson@gmail.com> - 2013-07-19 17:44 -0400
Re: Find and Replace Simplification Dave Angel <davea@davea.name> - 2013-07-19 18:45 -0400
Re: Find and Replace Simplification Joshua Landau <joshua@landau.ws> - 2013-07-20 12:16 +0100
Re: Find and Replace Simplification Serhiy Storchaka <storchaka@gmail.com> - 2013-07-20 14:48 +0300
Re: Find and Replace Simplification Serhiy Storchaka <storchaka@gmail.com> - 2013-07-20 14:57 +0300
Re: Find and Replace Simplification Devyn Collier Johnson <devyncjohnson@gmail.com> - 2013-07-20 08:41 -0400
Re: Find and Replace Simplification Devyn Collier Johnson <devyncjohnson@gmail.com> - 2013-07-20 08:50 -0400
Re: Find and Replace Simplification Joshua Landau <joshua@landau.ws> - 2013-07-20 18:03 +0100
Re: Find and Replace Simplification Dave Angel <davea@davea.name> - 2013-07-20 14:04 -0400
Re: Find and Replace Simplification Joshua Landau <joshua@landau.ws> - 2013-07-20 19:37 +0100
Re: Find and Replace Simplification Joshua Landau <joshua@landau.ws> - 2013-07-20 19:41 +0100
Re: Find and Replace Simplification Dave Angel <davea@davea.name> - 2013-07-20 17:56 -0400
Re: Find and Replace Simplification Joshua Landau <joshua@landau.ws> - 2013-07-20 23:33 +0100
Re: Find and Replace Simplification Serhiy Storchaka <storchaka@gmail.com> - 2013-07-21 10:44 +0300
Re: Find and Replace Simplification Joshua Landau <joshua@landau.ws> - 2013-07-21 12:29 +0100
Re: Find and Replace Simplification Serhiy Storchaka <storchaka@gmail.com> - 2013-07-21 15:28 +0300
Re: Find and Replace Simplification Joshua Landau <joshua@landau.ws> - 2013-07-21 13:49 +0100
csiph-web