Path: csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'url:pypi': 0.03; 'encoding': 0.05; 'mrab': 0.05; 'subject:Python': 0.06; 'indexing': 0.07; 'parser': 0.07; 'utf-8': 0.07; 'string': 0.09; 'compact': 0.09; 'differently.': 0.09; 'linear': 0.09; 'parsing': 0.09; 'strings.': 0.09; 'subject: [': 0.09; 'def': 0.12; "wouldn't": 0.14; 'encoding.': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'loop.': 0.16; 'parser.': 0.16; 'reason.': 0.16; 'string:': 0.16; 'wrote:': 0.18; 'module': 0.19; 'implementing': 0.19; "python's": 0.19; 'written': 0.21; 'seems': 0.21; '>>>': 0.22; 'initial': 0.24; 'nearly': 0.26; 'subject:/': 0.26; 'header:In-Reply-To:1': 0.27; 'am,': 0.29; 'character': 0.29; 'message-id:@mail.gmail.com': 0.30; "i'm": 0.30; 'run': 0.32; 'text': 0.33; 'url:python': 0.33; 'fri,': 0.33; 'could': 0.34; 'received:209.85': 0.35; 'common': 0.35; 'something': 0.35; 'operations': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'done': 0.36; 'method': 0.36; 'url:org': 0.36; 'received:209': 0.37; 'subject:]': 0.38; 'to:addr:python-list': 0.38; 'sure': 0.39; 'to:addr:python.org': 0.39; 'skip:p 20': 0.39; 'even': 0.60; 'ian': 0.60; 'impact': 0.61; 'simple': 0.61; 'more': 0.64; 'benefit': 0.68; 'mar': 0.68; 'fact,': 0.69; 'subject:long': 0.84; '2013': 0.98 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:x-received:in-reply-to:references:date:message-id :subject:from:to:content-type; bh=6dT+uvw+V5y3kiIrUr7IKhxA978hMIIcBAZGwkAPB4A=; b=tssJ3xEmCTaAQC1RJ2LHAnDC0DMUPsrppfLnNlaaR4D7WfOghRiQOMeMdod59jzP7C YQ61KVkOzyZ9voImAsU1VeVCh/fLIscN6FQNA3MxzVD0WkI97HuF7vTVueIgZIU5/u/d yhPmtPPfolKP20fAtgUgz4E3sENwfzG/Y4BwWo4oWkTeVySXCRgqAIVy1UrgrbhGloY+ uzJ+m6mLsEX4bMM2OKPONhN8ug1B0gx1vO/flRB6MIghyIsqXaOaNBUu2gMyemOMq6xz a+dA7NmmgxuChK7FdFstB56zkbcL6fi0DKEhEcBO5KVyZWU9ArRnzZdojv35vBFWCdBb hqmQ== MIME-Version: 1.0 X-Received: by 10.58.75.46 with SMTP id z14mr27131383vev.52.1364483265771; Thu, 28 Mar 2013 08:07:45 -0700 (PDT) In-Reply-To: <5154590C.9030902@mrabarnett.plus.com> References: <0b779c80-4f50-4716-8c30-47755c15f304@m12g2000yqp.googlegroups.com> <5153a12d$0$29998$c3e8da3$5496439d@news.astraweb.com> <987c4bd9-0e5e-4387-9c78-1075a77d3c47@c6g2000yqh.googlegroups.com> <5154590C.9030902@mrabarnett.plus.com> Date: Fri, 29 Mar 2013 02:07:45 +1100 Subject: Re: flaming vs accuracy [was Re: Performance of int/long in Python 3] From: Chris Angelico To: 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 47 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1364483268 news.xs4all.nl 6921 [2001:888:2000:d::a6]:60479 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:42142 On Fri, Mar 29, 2013 at 1:51 AM, MRAB wrote: > On 28/03/2013 12:11, Neil Hodgson wrote: >> >> Ian Foote: >> >>> Specifically, indexing a variable-length encoding like utf-8 is not >>> as efficient as indexing a fixed-length encoding. >> >> >> Many common string operations do not require indexing by character >> which reduces the impact of this inefficiency. UTF-8 seems like a >> reasonable choice for an internal representation to me. One benefit >> of UTF-8 over Python's flexible representation is that it is, on >> average, more compact over a wide set of samples. >> > Implementing the regex module (http://pypi.python.org/pypi/regex) would > have been more difficult if the internal representation had been UTF-8, > because of the need to decode, and the implementation would also have > been slower for that reason. In fact, nearly ALL string parsing operations would need to be done differently. The only method that I can think of that wouldn't be impacted is a linear state-machine parser - something that could be written inside a "for character in string" loop. text = [] def initial(c): global state if c=='<': state=tag else: text.append(c) def tag(c): global state if c=='>': state=initial state = initial for character in string: state(character) print(''.join(text)) I'm pretty sure this will run in O(N) time, even with UTF-8 strings. But it's an *extremely* simple parser. ChrisA