Path: csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!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; 'python.': 0.02; 'python,': 0.02; 'modified': 0.05; 'socket': 0.05; 'c++,': 0.07; 'lines.': 0.07; 'parser': 0.07; 'parsing': 0.07; 'rewrite': 0.07; 'subject:help': 0.07; 'python': 0.09; '(actually': 0.09; 'expectation': 0.09; 'happen.': 0.09; 'http,': 0.09; 'https': 0.09; 'splitting': 0.09; 'subject:skip:m 10': 0.09; 'subject:string': 0.09; 'contribute': 0.10; 'language': 0.14; 'properly': 0.15; 'result.': 0.15; 'sat,': 0.15; '"good': 0.16; '*good': 0.16; 'anyway).': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'measured': 0.16; 'module).': 0.16; 'opposite': 0.16; 'pythonic': 0.16; 'splits': 0.16; 'using,': 0.16; 'string': 0.17; 'wrote:': 0.17; 'byte': 0.17; 'bytes': 0.17; 'jan': 0.18; 'code,': 0.18; 'input': 0.18; 'module': 0.19; 'written': 0.20; 'parse': 0.22; "we'd": 0.24; 'machine': 0.24; 'header:In-Reply-To:1': 0.25; 'wrote': 0.26; 'am,': 0.27; 'handling': 0.27; 'implemented': 0.27; 'c++': 0.27; 'message-id:@mail.gmail.com': 0.27; "doesn't": 0.28; 'went': 0.28; 'all.': 0.28; 'chris': 0.28; 'fine': 0.28; '(since': 0.29; 'ansi': 0.29; 'though.': 0.29; 'probably': 0.29; 'code': 0.31; '(and': 0.32; 'control,': 0.33; 'point,': 0.33; 'handle': 0.33; 'to:addr :python-list': 0.33; 'version': 0.34; "can't": 0.34; 'changed': 0.34; 'received:google.com': 0.34; 'text': 0.34; 'faster': 0.35; 'machines': 0.35; 'protocol': 0.35; 'subject:?': 0.35; 'similar': 0.35; 'received:209.85': 0.35; 'something': 0.35; 'there': 0.35; 'but': 0.36; 'expensive': 0.36; "wasn't": 0.36; "didn't": 0.36; 'client': 0.36; 'test': 0.36; 'too': 0.36; 'problems': 0.36; 'level': 0.37; 'two': 0.37; 'uses': 0.37; 'being': 0.37; 'received:209': 0.37; 'data': 0.37; 'subject:: ': 0.38; 'easier': 0.38; 'performance': 0.39; 'to:addr:python.org': 0.39; 'header:Received:5': 0.40; 'think': 0.40; 'your': 0.60; 'most': 0.61; 'high': 0.61; 'subject:Need': 0.61; 'between': 0.63; 'different': 0.63; 'more': 0.63; 'subject:. ': 0.66; 'miss': 0.75; '2013': 0.84; 'divide': 0.84; 'running,': 0.84; 'seldom': 0.84; 'were,': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=maPfx+zfjzuhnW+r8xaAQbU1Ze3BI0m0l/BJ3lwmeGo=; b=I/lQ/3hAZ8FEebh6b8LxSQqfMR0FeNm/nYRCitpygOQaVVuwPC4nW8YAfZF2L2xRzs +d+a8477tmef1gNAvEoGiY/lJ6i+RlKFm5/B28G4jNDK9MIJPQ7QPi+r91AdrIuCde9W dzROboe7Ne63rwKHZ0D5Nd6AD65XiESmchJqYctR6/+qhoMbfWSi8bRbZLGP2EmHc5PC pr6i0KD5ghsUqpksOKI+UwxNE/wCAqOg1zh+SsSwjop2eFmfuJMwHG8iHLreDfSY3Fq1 5cGtm6jXCCppDtP9DZeh2AWSZ2udJoczqDF5MDkIE6IEfy+FkPznRE9UkzjGcW/t5R4H +1/g== MIME-Version: 1.0 In-Reply-To: References: Date: Sun, 6 Jan 2013 07:32:13 +1100 Subject: Re: Need a specific sort of string modification. Can someone help? 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: 40 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1357417943 news.xs4all.nl 6969 [2001:888:2000:d::a6]:56825 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:36206 On Sun, Jan 6, 2013 at 7:04 AM, Ian Kelly wrote: > On Sat, Jan 5, 2013 at 8:57 AM, Chris Angelico wrote: >> You miss my point, though. I went for simple Pythonic code, and never >> measured its performance, on the expectation that it's "good enough". >> Written in C, the state machine is probably WAY faster than splitting >> and then iterating. My C++ MUD client uses code similar to that to >> parse TELNET and ANSI codes from a stream of bytes in a socket (and >> one of its "states" is that there's no more data available, so wait on >> the socket); the rewrite in a high level language divides the string >> on "\xFF" for TELNET and "\x1B" for ANSI, working them separately, and >> then afterward splits on "\n" to divide into lines. The code's much >> less convoluted, it's easier to test different parts (because I can >> simply call the ANSI parser with a block of text), and on a modern >> computer, you can't see the performance difference (since you spend >> most of your time waiting for socket data anyway). > > Anecdotally and somewhat off-topic, when I wrote my own MUD client in > Python, I implemented both TELNET and ANSI parsing in Python using a > state machine processing one byte at a time (actually two state > machines - one at the protocol layer and one at the client layer; the > telnet module is a modified version of the twisted.conch.telnet > module). I was worried that the processing would be too slow in > Python. When I got it running, it turned out that there was a > noticeable lag between input being received and displayed. But when I > profiled the issue it actually turned out that the rich text control I > was using, which was written in C++, wasn't able to handle a large > buffer gracefully. The parsing code in Python did just fine and > didn't contribute to the lag issue at all. The opposite decision, the same result. Performance was *good enough*. With Gypsum, my early performance problems were almost completely solved by properly handling the expose-event and only painting the parts that changed (I don't use a rich text control, I use a GTK2.DrawingArea). Text processing of something that's come over a network is seldom a problem; if it were, we'd see noticeably slower downloads over HTTPS than HTTP, and that just doesn't happen. I think (though I can't prove) that crypto written in C is probably more expensive than ANSI parsing written in Python. ChrisA